Project

General

Profile

Bug #7479

WResource Multipart Request - Error parsing CGI request

Added by Michael Spellman over 2 years ago. Updated over 2 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

@

Also available in: Atom PDF