Project

General

Profile

Actions

Bug #7479

open

WResource Multipart Request - Error parsing CGI request

Added by Michael Spellman about 4 years ago. Updated about 4 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
03/04/2020
Due date:
% Done:

0%

Estimated time:

Description

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 occurred.

Error

occurred.

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.

HTTP Request:

@

POST /api/optimize-pdf HTTP/1.1

Host: 127.0.0.1:8083

Accept-Charset: UTF-8

Accept: /

User-Agent: Ktor client

Content-Type: multipart/form-data; boundary=*ktor-30844aa4-4a78-44b5-9429-f2ebb1b55165-ktor-1583318482396*; charset=UTF-8

Transfer-Encoding: chunked

148

---*ktor-30844aa4-4a78-44b5-9429-f2ebb1b55165-ktor-1583318482396*

Content-Disposition: form-data; name="user"

myuser

---*ktor-30844aa4-4a78-44b5-9429-f2ebb1b55165-ktor-1583318482396*

Content-Disposition: form-data; name="password"

password

---*ktor-30844aa4-4a78-44b5-9429-f2ebb1b55165-ktor-1583318482396*---

0

@

Actions #1

Updated by Roel Standaert about 4 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?

Actions

Also available in: Atom PDF