]> granicus.if.org Git - curl/commitdiff
Curl_add_custom_headers: support headers with no data
authorwarp kawada <warp.kawada@gmail.com>
Thu, 8 Sep 2011 22:39:39 +0000 (15:39 -0700)
committerDan Fandrich <dan@coneharvesters.com>
Tue, 13 Sep 2011 23:17:21 +0000 (16:17 -0700)
A custom HTTP header ending in a semicolon instead of a colon
will be treated as a header to be added without any data
portion.

RELEASE-NOTES
docs/curl.1
lib/http.c
tests/data/test4

index 859df65bf249604dcf566ed06519ab8e46d67bf4..ea9cd3785309796b5112ba9dd3f878a44ea2d3ee 100644 (file)
@@ -9,7 +9,7 @@ Curl and libcurl 7.22.1
 
 This release includes the following changes:
 
- o 
+ o Empty headers can be sent in HTTP requests by terminating with a semicolon
 
 This release includes the following bugfixes:
 
@@ -22,6 +22,6 @@ This release includes the following known bugs:
 This release would not have looked like this without help, code, reports and
 advice from friends like these:
 
+ Yukihiro Kawada 
 
         Thanks! (and sorry if I forgot to mention someone)
index d6fb9aa22f80c0a7652879387c043efa23ba9121..45e9f52ae3cc9069503f5ba78656be6a3e38f69d 100644 (file)
@@ -592,7 +592,9 @@ header will be used instead of the internal one. This allows you to make even
 trickier stuff than curl would normally do. You should not replace internally
 set headers without knowing perfectly well what you're doing. Remove an
 internal header by giving a replacement without content on the right side of
-the colon, as in: -H \&"Host:".
+the colon, as in: -H \&"Host:". If you send the custom header with no-value then
+its header must be terminated with a semicolon, such as \-H "X-Custom-Header;"
+to send "X-Custom-Header:".
 
 curl will make sure that each header you add/replace is sent with the proper
 end-of-line marker, you should thus \fBnot\fP add that as a part of the header
index b673296499e1573d70bfe28b388bcd7cb6d12c66..993900617476f5e0dfe88a7f43027c7033aaa73a 100644 (file)
@@ -1559,6 +1559,31 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
         }
       }
     }
+    else {
+      ptr = strchr(headers->data, ';');
+      if(ptr) {
+
+        ptr++; /* pass the semicolon */
+        while(*ptr && ISSPACE(*ptr))
+          ptr++;
+
+        if(*ptr) {
+          /* this may be used for something else in the future */
+        }
+        else {
+          if(*(--ptr) == ';') {
+            CURLcode result;
+
+            /* send no-value custom header if terminated by semicolon */
+            *ptr = ':';
+            result = Curl_add_bufferf(req_buffer, "%s\r\n",
+                                             headers->data);
+            if(result)
+              return result;
+          }
+        }
+      }
+    }
     headers = headers->next;
   }
   return CURLE_OK;
index ce6bfc8f0ef6c4149685a8afbcf47424aad8f4d1..df69d3274a2af21152891c87f5c32828a83fbadf 100644 (file)
@@ -30,7 +30,7 @@ http
 Replaced internal and added custom HTTP headers
  </name>
  <command>
- -H "extra-header: here" -H "Accept: replaced" http://%HOSTIP:%HTTPPORT/4
+ -H "extra-header: here" -H "Accept: replaced" -H "X-Custom-Header;" -H "X-Test: foo; " -H "X-Test:" -H "X-Test2: foo;" -H "X-Test3:  " -H "X-Test4;  " -H "X-Test5;ignored" http://%HOSTIP:%HTTPPORT/4
 </command>
 </client>
 
@@ -45,6 +45,9 @@ GET /4 HTTP/1.1
 Host: %HOSTIP:%HTTPPORT\r
 extra-header: here\r
 Accept: replaced\r
+X-Custom-Header:\r
+X-Test: foo; \r
+X-Test2: foo;\r
 \r
 </protocol>
 </verify>