azadkuh / qhttp

a light-weight and asynchronous HTTP library (both server & client) in Qt5 and c++14
MIT License
484 stars 158 forks source link

data() signal also sends HTML data from multipart/form-data #31

Open HappySeaFox opened 7 years ago

HappySeaFox commented 7 years ago

Hi. I use QHTTP to implement an HTTP server supporting POST requests with multipart/form-data MIME. I've noticed that the QHttpRequest::data() signal transmits extra HTML headers plus the posted file itself.

I post a video file like that:

> curl.exe "http://127.0.0.1:5000/video.mp4" -F "file=@H:\video.mp4"
* About to connect() to 127.0.0.1 port 5000 (#0)
*   Trying 127.0.0.1...
* Adding handle: conn: 0x68a8d0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x68a8d0) send_pipe: 1, recv_pipe: 0
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> POST /video.mp4 HTTP/1.1
> User-Agent: curl/7.32.0
> Host: 127.0.0.1:5000
> Accept: */*
> Content-Length: 129241953
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------39033ffa6ae3f23f
>
* Done waiting for 100-continue
< HTTP/1.1 200 OK
< connection: close
< date: Mon, 09 Jan 2017 20:27:44 GMT
<
* Closing connection 0

In data() signal I write all the incoming data into a file. After that in the file I see

--------------------------39033ffa6ae3f23f
Content-Disposition: form-data; name="file"; filename="video.mp4"
Content-Type: application/octet-stream

binary video data....
demiantres commented 7 years ago

This is normal behavior with multi-part forms. You have to parse the body.