]> granicus.if.org Git - curl/commitdiff
HTTP: use chunked Transfer-Encoding for HTTP_POST if size unknown
authorBalazs Kovacsics <balazs.kovacsics@ericsson.com>
Mon, 22 Jul 2019 12:37:37 +0000 (14:37 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 29 Jul 2019 11:18:53 +0000 (13:18 +0200)
If using the read callback for HTTP_POST, and POSTFIELDSIZE is not set,
automatically add a Transfer-Encoding: chunked header, same as it is
already done for HTTP_PUT, HTTP_POST_FORM and HTTP_POST_MIME.  Update
test 1514 according to the new behaviour.

Closes #4138

docs/libcurl/opts/CURLOPT_POST.3
lib/http.c
tests/data/test1514

index 66e5c6ac734a3394e41466866d7832ab1b28300e..2f3d43d6773b06dcb3c3043d7583e93d3e2ccbc6 100644 (file)
@@ -5,7 +5,7 @@
 .\" *                            | (__| |_| |  _ <| |___
 .\" *                             \___|\___/|_| \_\_____|
 .\" *
-.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+.\" * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
 .\" *
 .\" * This software is licensed as described in the file COPYING, which
 .\" * you should have received as part of this distribution. The terms
@@ -55,7 +55,8 @@ If you use POST to an HTTP 1.1 server, you can send data without knowing the
 size before starting the POST if you use chunked encoding. You enable this by
 adding a header like "Transfer-Encoding: chunked" with
 \fICURLOPT_HTTPHEADER(3)\fP. With HTTP 1.0 or without chunked transfer, you
-must specify the size in the request.
+must specify the size in the request. (Since 7.66.0, libcurl will
+automatically use chunked encoding for POSTs if the size is unknown.)
 
 When setting \fICURLOPT_POST(3)\fP to 1, libcurl will automatically set
 \fICURLOPT_NOBODY(3)\fP and \fICURLOPT_HTTPGET(3)\fP to 0.
index 36e94f762f846361a601729a74894f79968a5eca..065a26817914194a2db61b6e5a7a4d409229fc89 100644 (file)
@@ -2247,8 +2247,9 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
   else {
     if((conn->handler->protocol & PROTO_FAMILY_HTTP) &&
        (((httpreq == HTTPREQ_POST_MIME || httpreq == HTTPREQ_POST_FORM) &&
-       http->postsize < 0) ||
-       (data->set.upload && data->state.infilesize == -1))) {
+         http->postsize < 0) ||
+        ((data->set.upload || httpreq == HTTPREQ_POST) &&
+         data->state.infilesize == -1))) {
       if(conn->bits.authneg)
         /* don't enable chunked during auth neg */
         ;
index 38f5da61f8151d441b9012ff5d5e3b73017d5a3d..6c09ae3b0e107ff38bf7948560049ce786903e4b 100644 (file)
@@ -4,13 +4,14 @@
 HTTP
 HTTP POST
 Content-Length
+chunked Transfer-Encoding
 </keywords>
 </info>
 
 # Server-side
 <reply>
 <data nocheck="yes">
-HTTP/1.1 411 Length Required\r
+HTTP/1.1 200 OK\r
 Date: Sun, 19 Jan 2014 18:50:58 GMT\r
 Server: test-server/fake swsclose\r
 Connection: close\r
@@ -36,13 +37,27 @@ http://%HOSTIP:%HTTPPORT/1514
 # Verify data after the test has been "shot"
 <verify>
 # Content-Length header is not present
+# Transfer-Encoding header is added automatically
 <protocol>
 POST /1514 HTTP/1.1\r
 Host: %HOSTIP:%HTTPPORT\r
 Accept: */*\r
+Transfer-Encoding: chunked\r
 Content-Type: application/x-www-form-urlencoded\r
 Expect: 100-continue\r
 \r
+1\r
+d\r
+1\r
+u\r
+1\r
+m\r
+1\r
+m\r
+1\r
+y\r
+0\r
+\r
 </protocol>
 </verify>
 </testcase>