1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

TE: do the Connection: header

When TE: is inserted in the request, we must add a "Connection: TE" as
well to be HTTP 1.1 compliant. If a custom Connection: header is passed
in, we must use that and only append TE to it. Test case 1125 verifies
TE: + custom Connection:.
This commit is contained in:
Daniel Stenberg 2011-04-11 16:30:14 +02:00
parent be973b6f91
commit 9d191a6a40
6 changed files with 90 additions and 5 deletions

View File

@ -1533,6 +1533,11 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn,
we will force length zero then */ we will force length zero then */
checkprefix("Content-Length", headers->data)) checkprefix("Content-Length", headers->data))
; ;
else if(conn->allocptr.te &&
/* when asking for Transfer-Encoding, don't pass on a custom
Connection: */
checkprefix("Connection", headers->data))
;
else { else {
CURLcode result = Curl_add_bufferf(req_buffer, "%s\r\n", CURLcode result = Curl_add_bufferf(req_buffer, "%s\r\n",
headers->data); headers->data);
@ -1728,14 +1733,21 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
#if 0 if(Curl_checkheaders(data, "TE:")) {
if(!Curl_checkheaders(data, "TE:")) { /* When we insert a TE: header in the request, we must also insert TE in a
Connection: header, so we need to merge the custom provided Connection:
header and prevent the original to get sent */
char *cptr = Curl_checkheaders(data, "Connection:");
Curl_safefree(conn->allocptr.te); Curl_safefree(conn->allocptr.te);
conn->allocptr.te = aprintf("TE: %s\r\n", "gzip");
/* Create the (updated) Connection: header */
conn->allocptr.te = cptr? aprintf("%s, TE\r\n", cptr):
strdup("Connection: TE\r\n");
if(!conn->allocptr.te) if(!conn->allocptr.te)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
#endif
ptr = Curl_checkheaders(data, "Transfer-Encoding:"); ptr = Curl_checkheaders(data, "Transfer-Encoding:");
if(ptr) { if(ptr) {

View File

@ -71,7 +71,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \
test1203 test1117 test1118 test1119 test1120 test1300 test1301 test1302 \ test1203 test1117 test1118 test1119 test1120 test1300 test1301 test1302 \
test1303 test320 test321 test322 test323 test324 test1121 test581 test580 \ test1303 test320 test321 test322 test323 test324 test1121 test581 test580 \
test1304 test1305 test1306 test1307 test582 test583 test808 test809 \ test1304 test1305 test1306 test1307 test582 test583 test808 test809 \
test810 test811 test812 test813 test584 test1122 test1123 test1124 test810 test811 test812 test813 test584 test1122 test1123 test1124 test1125
filecheck: filecheck:
@mkdir test-place; \ @mkdir test-place; \

View File

@ -62,6 +62,7 @@ http://%HOSTIP:%HTTPPORT/1122 -H "TE: gzip"
GET /1122 HTTP/1.1 GET /1122 HTTP/1.1
Host: %HOSTIP:%HTTPPORT Host: %HOSTIP:%HTTPPORT
Accept: */* Accept: */*
Connection: TE
TE: gzip TE: gzip
</protocol> </protocol>

View File

@ -192,6 +192,7 @@ http://%HOSTIP:%HTTPPORT/1123 -H "TE: deflate, gzip"
GET /1123 HTTP/1.1 GET /1123 HTTP/1.1
Host: %HOSTIP:%HTTPPORT Host: %HOSTIP:%HTTPPORT
Accept: */* Accept: */*
Connection: TE
TE: deflate, gzip TE: deflate, gzip
</protocol> </protocol>

View File

@ -61,6 +61,7 @@ http://%HOSTIP:%HTTPPORT/1124 -H "TE: gzip"
GET /1124 HTTP/1.1 GET /1124 HTTP/1.1
Host: %HOSTIP:%HTTPPORT Host: %HOSTIP:%HTTPPORT
Accept: */* Accept: */*
Connection: TE
TE: gzip TE: gzip
</protocol> </protocol>

70
tests/data/test1125 Normal file
View File

@ -0,0 +1,70 @@
<testcase>
<info>
<keywords>
HTTP
HTTP GET
compressed
Transfer-Encoding
</keywords>
</info>
#
# Server-side
<reply>
<data base64="yes">
SFRUUC8xLjEgMjAwIE9LDQpEYXRlOiBNb24sIDI5IE5vdiAyMDA0IDIxOjU2OjUzIEdNVA0KU2Vy
dmVyOiBBcGFjaGUvMS4zLjMxIChEZWJpYW4gR05VL0xpbnV4KSBtb2RfZ3ppcC8xLjMuMjYuMWEg
UEhQLzQuMy45LTEgbW9kX3NzbC8yLjguMjAgT3BlblNTTC8wLjkuN2QgbW9kX3BlcmwvMS4yOQ0K
VmFyeTogQWNjZXB0LUVuY29kaW5nDQpDb250ZW50LVR5cGU6IHRleHQvaHRtbDsgY2hhcnNldD1J
U08tODg1OS0xDQpUcmFuc2Zlci1FbmNvZGluZzogZ3ppcA0KQ29udGVudC1MZW5ndGg6IDQ0DQoN
Ch+LCAh5nqtBAANsYWxhbGEAy8nMS1Uw5FLIAdFGXAoQhjEXAAoCcWAYAAAA
</data>
<datacheck>
HTTP/1.1 200 OK
Date: Mon, 29 Nov 2004 21:56:53 GMT
Server: Apache/1.3.31 (Debian GNU/Linux) mod_gzip/1.3.26.1a PHP/4.3.9-1 mod_ssl/2.8.20 OpenSSL/0.9.7d mod_perl/1.29
Vary: Accept-Encoding
Content-Type: text/html; charset=ISO-8859-1
Transfer-Encoding: gzip
Content-Length: 44
line 1
line 2
line 3
</datacheck>
</reply>
#
# Client-side
<client>
<features>
libz
</features>
<server>
http
</server>
<name>
HTTP GET transfer-encoding with custom Connection:
</name>
<command>
http://%HOSTIP:%HTTPPORT/1125 -H "TE: gzip" -H "Connection: close"
</command>
</client>
#
# Verify data after the test has been "shot"
<verify>
<strip>
^User-Agent:.*
</strip>
<protocol>
GET /1125 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
Connection: close, TE
TE: gzip
</protocol>
</verify>
</testcase>