vibe.d throws HTTPServerErrorInfo if a file upload is too large before any of my code executes
Steven Schveighoffer
schveiguy at gmail.com
Sat Mar 13 21:22:05 UTC 2021
On 3/13/21 3:53 PM, Chris Bare wrote:
> I'm using vibe-d-0.9.3. I have file uploads working fine, but if the
> file it too large, it triggers this:
> enforceBadRequest(settings.maxRequestSize <= 0 || contentLength <=
> settings.maxRequestSize, "Request size too big");
>
> inside the handleRequest function, long before my handler function is
> called.
>
> This prevents me from returning a useful error. Vibe sends a 400 error
> page:
>
> <!DOCTYPE html>
> <html>
> <head>
> <title>Error</title>
> </head>
> <body>
> <h1>Error Happened</h1><p>400</p><p></p><p>Request size too
> big</p><p>Request size too
> big</p><p>/home/chris/.dub/packages/vibe-d-0.9.3/vibe-d/http/vibe/http/server.d:2237</p>
>
> </body>
> </html>
>
> Does anyone have a solution for this?
The boolean condition identifies exactly how to fix it, set
maxRequestSize to -1 to disable, or to a value that's large enough.
e.g.:
auto settings = new HTTPServerSettings;
settings.bindAddresses = ["0.0.0.0"];
.... // and all the other stuff
settings.maxRequestSize = 50_000_000;
auto listener = listenHTTP(settings, router);
...
> I guess I could catch the error in my main function, but I wouldn't know
> the context.
I would think that the error should be handled fine by vibe-d. Note, you
can override error handling to put out a page of your choice based on
the exception.
> Also, since Errors are not intended to be caught, shouldn't this be an
> Exception instead?
The thing you should get is HTTPStatusException, not an Error.
-Steve
More information about the Digitalmars-d
mailing list