cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: HTTP POST: fail early if unknown data size (read function)

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sun, 12 Jan 2014 00:19:47 +0100 (CET)

On Sat, 11 Jan 2014, CÚdric Deltheil wrote:

> When performing a standard HTTP POST (w/o chunked encoding) with a custom
> read function, a common mistake is to forget to explicitly set the POST size
> via `CURLOPT_POSTFIELDSIZE`.
>
> This results in libcurl sending a negative content length:
>
> Content-Length: -1
>
> , which gives a bad request.
>
> The question is: should we prevent libcurl to send the request by failing
> early?

Yes I think so. Sending -1 is plain wrong.

> Before sending a patch, I was wondering if `CURLE_UPLOAD_FAILED` would be
> the best error code to use there.

Sure. With a decent failf() as well it should be fine.

It'd also be great to have a test case or two for this. See tests/libtest/ for
inspiration!

-- 
  / daniel.haxx.se

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-01-12