Commit a5d99494 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

http: always send Host: header as first header

...after the method line:

 "Since the Host field-value is critical information for handling a
 request, a user agent SHOULD generate Host as the first header field
 following the request-line." / RFC 7230 section 5.4

Additionally, this will also make libcurl ignore multiple specified
custom Host: headers and only use the first one. Test 1121 has been
updated accordingly

Bug: http://curl.haxx.se/bug/view.cgi?id=1491
Reported-by: Rainer Canavan
parent 143acd62
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -2016,6 +2016,13 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
    }
#endif

    if(strcmp("Host:", ptr)) {
      conn->allocptr.host = aprintf("%s\r\n", ptr);
      if(!conn->allocptr.host)
        return CURLE_OUT_OF_MEMORY;
    }
    else
      /* when clearing the header */
      conn->allocptr.host = NULL;
  }
  else {
@@ -2285,11 +2292,11 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
    Curl_add_bufferf(req_buffer,
                     "%s" /* ftp typecode (;type=x) */
                     " HTTP/%s\r\n" /* HTTP version */
                     "%s" /* host */
                     "%s" /* proxyuserpwd */
                     "%s" /* userpwd */
                     "%s" /* range */
                     "%s" /* user agent */
                     "%s" /* host */
                     "%s" /* accept */
                     "%s" /* TE: */
                     "%s" /* accept-encoding */
@@ -2299,6 +2306,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)

                     ftp_typecode,
                     httpstring,
                     (conn->allocptr.host?conn->allocptr.host:""),
                     conn->allocptr.proxyuserpwd?
                     conn->allocptr.proxyuserpwd:"",
                     conn->allocptr.userpwd?conn->allocptr.userpwd:"",
@@ -2308,7 +2316,6 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
                      *data->set.str[STRING_USERAGENT] &&
                      conn->allocptr.uagent)?
                     conn->allocptr.uagent:"",
                     (conn->allocptr.host?conn->allocptr.host:""),
                     http->p_accept?http->p_accept:"",
                     conn->allocptr.te?conn->allocptr.te:"",
                     (data->set.str[STRING_ENCODING] &&
+2 −2
Original line number Diff line number Diff line
@@ -85,17 +85,17 @@ test
</strip>
<protocol>
GET http://%HOSTIP:%HTTPPORT/1001 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Content-Range: bytes 2-4/5
User-Agent: curl/7.12.1-CVS (i686-pc-linux-gnu) libcurl/7.12.1-CVS OpenSSL/0.9.6b ipv6 zlib/1.1.4 GSS libidn/0.4.6
Host: %HOSTIP:%HTTPPORT
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 0

GET http://%HOSTIP:%HTTPPORT/1001 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Authorization: Digest username="auser", realm="testrealm", nonce="1053604144", uri="/1001", response="6af4d89c952f4dd4cc215a6878dc499d"
Content-Range: bytes 2-4/5
Host: %HOSTIP:%HTTPPORT
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 3
+3 −3
Original line number Diff line number Diff line
@@ -84,17 +84,17 @@ test
</strip>
<protocol>
GET http://%HOSTIP:%HTTPPORT/1002.upload1 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Content-Range: bytes 2-4/5
User-Agent: curl/7.12.1-CVS (i686-pc-linux-gnu) libcurl/7.12.1-CVS OpenSSL/0.9.6b ipv6 zlib/1.1.4 GSS libidn/0.4.6
Host: %HOSTIP:%HTTPPORT
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 0

GET http://%HOSTIP:%HTTPPORT/1002.upload1 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Authorization: Digest username="auser", realm="testrealm", nonce="1053604144", uri="/1002.upload1", response="198aa9b6acb4b0c71d02a197a5e41f54"
Content-Range: bytes 2-4/5
Host: %HOSTIP:%HTTPPORT
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 3
@@ -102,10 +102,10 @@ Expect: 100-continue

st
GET http://%HOSTIP:%HTTPPORT/1002.upload2 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Authorization: Digest username="auser", realm="testrealm", nonce="1053604144", uri="/1002.upload2", response="d711f0d2042786d930de635ba0d1a1d0"
Content-Range: bytes 2-4/5
User-Agent: curl/7.16.1
Host: %HOSTIP:%HTTPPORT
Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 3
+1 −1
Original line number Diff line number Diff line
@@ -94,9 +94,9 @@ a second line
line three
four is the number of lines
PUT /1030 HTTP/1.1
Host: %HOSTIP:%HTTPPORT
Authorization: Digest username="testuser", realm="gimme all yer s3cr3ts", nonce="11223344", uri="/1030", response="01cb59db1ddaac246b072d5f5f0716d9"
User-Agent: curl/7.10.5 (i686-pc-linux-gnu) libcurl/7.10.5 OpenSSL/0.9.7a ipv6 zlib/1.1.3
Host: %HOSTIP:%HTTPPORT
Accept: */*
Content-Length: 85
Expect: 100-continue
+1 −1
Original line number Diff line number Diff line
@@ -47,8 +47,8 @@ HTTP HEAD with --range
</strip>
<protocol>
HEAD /1032 HTTP/1.1
Range: bytes=1-3
Host: %HOSTIP:%HTTPPORT
Range: bytes=1-3
Accept: */*

</protocol>
Loading