diff options
author | warp kawada <warp.kawada@gmail.com> | 2011-09-08 15:39:39 -0700 |
---|---|---|
committer | Dan Fandrich <dan@coneharvesters.com> | 2011-09-13 16:17:21 -0700 |
commit | aff70e2e9534eecb9e756d2104efa52e5d8b0462 (patch) | |
tree | 86069726bec4662e6788a5e76814eacf6c0a55f1 | |
parent | 6790a543d4b692e0f62971804606fdcbcf84a292 (diff) |
Curl_add_custom_headers: support headers with no data
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.
-rw-r--r-- | RELEASE-NOTES | 4 | ||||
-rw-r--r-- | docs/curl.1 | 4 | ||||
-rw-r--r-- | lib/http.c | 25 | ||||
-rw-r--r-- | tests/data/test4 | 5 |
4 files changed, 34 insertions, 4 deletions
diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 859df65bf..ea9cd3785 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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) diff --git a/docs/curl.1 b/docs/curl.1 index d6fb9aa22..45e9f52ae 100644 --- a/docs/curl.1 +++ b/docs/curl.1 @@ -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 diff --git a/lib/http.c b/lib/http.c index b67329649..993900617 100644 --- a/lib/http.c +++ b/lib/http.c @@ -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; diff --git a/tests/data/test4 b/tests/data/test4 index ce6bfc8f0..df69d3274 100644 --- a/tests/data/test4 +++ b/tests/data/test4 @@ -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
extra-header: here
Accept: replaced
+X-Custom-Header:
+X-Test: foo;
+X-Test2: foo;
</protocol> </verify> |