digitalmars.D - vibe.d throws HTTPServerErrorInfo if a file upload is too large before
- Chris Bare (24/24) Mar 13 2021 I'm using vibe-d-0.9.3. I have file uploads working fine, but if
- Steven Schveighoffer (15/44) Mar 13 2021 The boolean condition identifies exactly how to fix it, set
- Chris Bare (8/15) Mar 14 2021 On Saturday, 13 March 2021 at 21:22:05 UTC, Steven Schveighoffer
- Steven Schveighoffer (14/25) Mar 14 2021 Hm... looks like it's failing before establishing the session. It's
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? I guess I could catch the error in my main function, but I wouldn't know the context. Also, since Errors are not intended to be caught, shouldn't this be an Exception instead?
Mar 13 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/ht p/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
Mar 13 2021
On Saturday, 13 March 2021 at 21:22:05 UTC, Steven Schveighoffer wrote: I don't want to change the size limit.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.It does return my custom error page, but that is not what I want to return. at that point I have no session so I can't send back the page with the form that was submitted marked with an error.You are right, it causes an HTTPStatusException.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
Mar 14 2021
On 3/14/21 4:55 PM, Chris Bare wrote:On Saturday, 13 March 2021 at 21:22:05 UTC, Steven Schveighoffer wrote: I don't want to change the size limit.Well, I'm not sure what you expect then.Hm... looks like it's failing before establishing the session. It's doing it based on the Content-Length. The only way I can imagine to make it work without changing vibe-d is to set the max size to -1, and then handle it manually in your code. Technically, the fact that the request is too large is really an anti-denial-of-service measure, and arguably you could say that you shouldn't look at any requests bigger than your maximum size. To draw a comparison, php will actually not send ANYTHING back if the max request size is exceeded. Possibly you could file an enhancement request on vibe-d to still process the session even if the request size is too big. -SteveI 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.It does return my custom error page, but that is not what I want to return. at that point I have no session so I can't send back the page with the form that was submitted marked with an error.
Mar 14 2021