WResource Multipart Request - Error parsing CGI request
When I send a multipart HTTP request with or without a file attached to a Resource class derived from WResource, I receive the following error message before any of my code is run:
Error parsing CGI request: CgiParser: reached end of input while seeking end of headers or content. Format of CGI input is wrong
That error message appears to come from CgiParser.C and is related to the boundary parsing in multipart requests: https://github.com/emweb/wt/blob/master/src/web/CgiParser.C
I ran netcat and discovered a `0` at the end of the request, as described by the author of this blog post, who had the same issue: https://blog.aeste.my/2019/08/12/multipart-form-data/
He was using Poco Http Library, I am using a ktor HTTP client library. It appears that he was able to solve it by setting the HTTP protocol version to 1.0.
POST /api/optimize-pdf HTTP/1.1
User-Agent: Ktor client
Content-Type: multipart/form-data; boundary=*ktor-30844aa4-4a78-44b5-9429-f2ebb1b55165-ktor-1583318482396*; charset=UTF-8
Content-Disposition: form-data; name="user"
Content-Disposition: form-data; name="password"
Updated by Roel Standaert over 2 years ago
wthttp at the moment doesn't accept requests that use chunked encoding. We should probably return something else instead when we're getting a request that uses chunked encoding, though.
So we should either:
- Accept chunked encoding. It seems that the RFC does require that chunked encoding is supported by the server.
- Or: reject chunked encoding instead of giving the above error
The reason why he was probably able to solve his issue when switching to HTTP/1.0 is because HTTP/1.0 doesn't support chunked encoding.
I don't know if ktor can be configured to not use chunked encoding in the meantime?