]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4501: HTTP/1.1: normalize Host header
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 9 May 2016 13:11:21 +0000 (01:11 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 9 May 2016 13:11:21 +0000 (01:11 +1200)
src/client_side.cc

index a6242f7e51472ce6f59a3e22d4cdf78a93a51148..1ec92516c836aa2c8cff76c165bf57516ea8614b 100644 (file)
@@ -2740,6 +2740,23 @@ clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *c
         goto finish;
     }
 
+    // when absolute-URI is provided Host header should be ignored. However
+    // some code still uses Host directly so normalize it.
+    // For now preserve the case where Host is completely absent.
+    if (request->header.has(HDR_HOST)) {
+        const char *host = request->header.getStr(HDR_HOST);
+        MemBuf authority;
+        authority.init();
+        if (request->port != urlDefaultPort(request->protocol))
+            authority.Printf("%s:%d", request->GetHost(), request->port);
+        else
+            authority.Printf("%s", request->GetHost());
+        debugs(33, 5, "URL domain " << authority.buf << " overrides header Host: " << host);
+        // URL authority overrides Host header
+        request->header.delById(HDR_HOST);
+        request->header.putStr(HDR_HOST, authority.buf);
+    }
+
     request->clientConnectionManager = conn;
 
     request->flags.accelerated = http->flags.accel;