curl-users
Re: bug/problem: curl sending extra data with `--upload-file - --header "Content-Lenght: XXX"` ?
Date: Mon, 2 Jan 2017 17:33:07 +0100
On Mon, Jan 02, 2017 at 12:45:54PM +0100, Tomas Pospisek wrote:
> TLDR; curl seem to be adding extra data to the payload when using
> `--upload-file -` together with `--header "Content-Length: XXX"`.
>
> The below is a reduced example. In reality we need to upload a file,
> which is very large, whose size we know, but that is not available
> locally on disk. Therefore we pass the contents to upload to curl via
> STDIN and we set the (known) content length header.
[...]
> You'll note in the trace above there's "31 61 0d 0a" preceeding the
> "Hello, my name is...".
The trace you supplied shows that the transfer is being performed with chunked
encoding, which adds the "31 61 0d 0a" header. To quote the HTTP RFC:
The Content-Length header field MUST NOT be sent
if these two lengths are different (i.e., if a Transfer-Encoding
header field is present).
so the condition set up by the flags is invalid. Why are you setting the
Content-Length? Just let curl handle that and the chunked transfer should work
fine.
> Now my questions are:
> * is this me using curl the wrong way?
Yes.
> * what would be the correct way to upload a file via stdin?
Just let curl handle the headers on its own instead of trying to outsmart it.
> * is this a curl bug?
Doesn't look like it. GIGO.
>>> Dan
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ: https://curl.haxx.se/docs/faq.html
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-01-02