]> granicus.if.org Git - curl/commitdiff
http: fix missing 'Content-Length: 0' while negotiating auth
authorIsaac Boukris <iboukris@gmail.com>
Fri, 3 Feb 2017 12:30:26 +0000 (14:30 +0200)
committerJay Satiro <raysatiro@yahoo.com>
Fri, 17 Feb 2017 07:32:16 +0000 (02:32 -0500)
- While negotiating auth during PUT/POST if a user-specified
  Content-Length header is set send 'Content-Length: 0'.

This is what we do already in HTTPREQ_POST_FORM and what we did in the
HTTPREQ_POST case (regression since afd288b).

Prior to this change no Content-Length header would be sent in such a
case.

Bug: https://curl.haxx.se/mail/lib-2017-02/0006.html
Reported-by: Dominik Hölzl
Closes https://github.com/curl/curl/pull/1242

lib/http.c
tests/data/Makefile.inc
tests/data/test1284 [new file with mode: 0644]
tests/data/test1285 [new file with mode: 0644]

index 2066520e7645de3e5ddb7d3149f208b5d820ff98..8db86cd84df94de218ad35e87a760f3ac00a51e9 100644 (file)
@@ -2512,7 +2512,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
       postsize = data->state.infilesize;
 
     if((postsize != -1) && !data->req.upload_chunky &&
-       !Curl_checkheaders(conn, "Content-Length:")) {
+       (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length:"))) {
       /* only add Content-Length if not uploading chunked */
       result = Curl_add_bufferf(req_buffer,
                                 "Content-Length: %" CURL_FORMAT_CURL_OFF_T
@@ -2564,7 +2564,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
        we don't upload data chunked, as RFC2616 forbids us to set both
        kinds of headers (Transfer-Encoding: chunked and Content-Length) */
     if((postsize != -1) && !data->req.upload_chunky &&
-       !Curl_checkheaders(conn, "Content-Length:")) {
+       (conn->bits.authneg || !Curl_checkheaders(conn, "Content-Length:"))) {
       /* we allow replacing this header if not during auth negotiation,
          although it isn't very wise to actually set your own */
       result = Curl_add_bufferf(req_buffer,
index c8334c8f32cce1a198b0a51d2157e107b34cb972..953916d9740f005b28579d0c852392e8ac66b44a 100644 (file)
@@ -130,7 +130,7 @@ test1236 test1237 test1238 test1239 test1240 test1241 test1242 test1243 \
 test1244 test1245 test1246 test1247 test1248 test1249 test1250 test1251 \
 test1252 test1253 test1254 test1255 test1256 test1257 test1258 test1259 \
 \
-test1280 test1281 test1282 test1283 \
+test1280 test1281 test1282 test1283 test1284 test1285 \
 \
 test1300 test1301 test1302 test1303 test1304 test1305 test1306 test1307 \
 test1308 test1309 test1310 test1311 test1312 test1313 test1314 test1315 \
diff --git a/tests/data/test1284 b/tests/data/test1284
new file mode 100644 (file)
index 0000000..8437a40
--- /dev/null
@@ -0,0 +1,89 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+HTTP Digest auth
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data>
+HTTP/1.1 401 authentication please swsbounce\r
+Server: Microsoft-IIS/6.0\r
+WWW-Authenticate: Digest realm="testrealm", nonce="1053604144"\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 0\r
+\r
+</data>
+<data1000>
+HTTP/1.1 200 A OK\r
+Server: Microsoft-IIS/6.0\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 3\r
+\r
+ok
+</data1000>
+
+<datacheck>
+HTTP/1.1 401 authentication please swsbounce\r
+Server: Microsoft-IIS/6.0\r
+WWW-Authenticate: Digest realm="testrealm", nonce="1053604144"\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 0\r
+\r
+HTTP/1.1 200 A OK\r
+Server: Microsoft-IIS/6.0\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 3\r
+\r
+ok
+</datacheck>
+
+</reply>
+
+# Client-side
+<client>
+#
+<server>
+http
+</server>
+<features>
+!SSPI
+crypto
+</features>
+<name>
+HTTP POST --digest with user-specified Content-Length header
+</name>
+# This test is to ensure 'Content-Length: 0' is sent while negotiating auth
+# even when there is a user-specified Content-Length header.
+# https://github.com/curl/curl/pull/1242
+<command>
+-H "Content-Length: 11" -u auser:apasswd --digest -d "junkelijunk" http://%HOSTIP:%HTTPPORT/1284
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol nonewline="yes">
+POST /1284 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+Content-Length: 0\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+POST /1284 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Authorization: Digest username="auser", realm="testrealm", nonce="1053604144", uri="/1284", response="5763079608de439072861a59ac733515"\r
+Accept: */*\r
+Content-Length: 11\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+junkelijunk
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/data/test1285 b/tests/data/test1285
new file mode 100644 (file)
index 0000000..16c6623
--- /dev/null
@@ -0,0 +1,97 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP PUT
+HTTP Digest auth
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data>
+HTTP/1.1 401 authentication please swsbounce\r
+Server: Microsoft-IIS/6.0\r
+WWW-Authenticate: Digest realm="testrealm", nonce="1053604144"\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 0\r
+\r
+</data>
+<data1000>
+HTTP/1.1 200 A OK\r
+Server: Microsoft-IIS/6.0\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 3\r
+\r
+ok
+</data1000>
+
+<datacheck>
+HTTP/1.1 401 authentication please swsbounce\r
+Server: Microsoft-IIS/6.0\r
+WWW-Authenticate: Digest realm="testrealm", nonce="1053604144"\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 0\r
+\r
+HTTP/1.1 200 A OK\r
+Server: Microsoft-IIS/6.0\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 3\r
+\r
+ok
+</datacheck>
+
+</reply>
+
+# Client-side
+<client>
+#
+<server>
+http
+</server>
+<features>
+!SSPI
+crypto
+</features>
+<name>
+HTTP PUT --digest with user-specified Content-Length header
+</name>
+# This test is to ensure 'Content-Length: 0' is sent while negotiating auth
+# even when there is a user-specified Content-Length header.
+# https://github.com/curl/curl/pull/1242
+<command>
+-H "Content-Length: 85" -u auser:apasswd --digest -T log/put1285 http://%HOSTIP:%HTTPPORT/1285
+</command>
+<file name="log/put1285">
+This is data we upload with PUT
+a second line
+line three
+four is the number of lines
+</file>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+PUT /1285 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+Content-Length: 0\r
+\r
+PUT /1285 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Authorization: Digest username="auser", realm="testrealm", nonce="1053604144", uri="/1285", response="dc185587d5e8391b347eef194c2a3cd6"\r
+Accept: */*\r
+Content-Length: 85\r
+Expect: 100-continue\r
+\r
+This is data we upload with PUT
+a second line
+line three
+four is the number of lines
+</protocol>
+</verify>
+</testcase>