]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Regression fix: vhost and defaultsite causing vport to be ignored
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 25 Jul 2011 01:38:40 +0000 (19:38 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 25 Jul 2011 01:38:40 +0000 (19:38 -0600)
Instead of dropping it completely we should be sanely combining them like
Squid-2 does for most cases. This appears to have been lost while removing
the getmyHostname() from the process and reducing the
prepareTransparentUrl code.

This fix makes vport apply even if vhost was used. It will modify the
Host: header contents according to the documented vport semantics.

This fix makes vport apply even if defaultsite= was used. It will append
the specified port to the domain name given. Domains with port attached
are not supported and will produce invalid URLs.
TODO: detect this case while parsing the initial config and warn.

src/cf.data.pre
src/client_side.cc

index 6383ca86cabe958636f5a41e997f14811be17366..95b0af907cdd5ce84c4aa5ea1496ce3bd69ac275 100644 (file)
@@ -1169,14 +1169,16 @@ DOC_START
                        accelerators should consider the default.
                        Implies accel.
 
-          vhost        Accelerator mode using Host header for virtual
-                       domain support. Implies accel.
+          vhost        Accelerator mode using Host header for virtual domain support.
+                       Also uses the port as specified in Host: header unless
+                       overridden by the vport option. Implies accel.
 
-          vport        Accelerator with IP based virtual host support.
-                       Implies accel.
+          vport        Virtual host port support. Using the http_port number
+                       instead of the port passed on Host: headers. Implies accel.
 
-          vport=NN     As above, but uses specified port number rather
-                       than the http_port number. Implies accel.
+          vport=NN     Virtual host port support. Using the specified port
+                       number instead of the port passed on Host: headers.
+                       Implies accel.
 
           protocol=    Protocol to reconstruct accelerated requests with.
                        Defaults to http.
index c68564159d9f21cc3a401e23d0ca3be27e7d8423..a91a12c4bdc46b3d615963f6249409e9b66fad0b 100644 (file)
@@ -1874,9 +1874,26 @@ prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url,
         return;
     }
 
+    if (vport < 0)
+        vport = http->getConn()->me->local.GetPort();
+
     const bool switchedToHttps = conn->switchedToHttps();
     const bool tryHostHeader = vhost || switchedToHttps;
     if (tryHostHeader && (host = mime_get_header(req_hdr, "Host")) != NULL) {
+        debugs(33, 5, "ACCEL VHOST REWRITE: vhost=" << host << " + vport=" << vport);
+        char thost[256];
+        if (vport > 0) {
+            thost[0] = '\0';
+            char *t = NULL;
+            if (host[strlen(host)] != ']' && (t = strrchr(host,':')) != NULL) {
+                strncpy(thost, host, (t-host));
+                snprintf(thost+(t-host), sizeof(thost)-(t-host), ":%d", vport);
+                host = thost;
+            } else if (!t) {
+                snprintf(thost, sizeof(thost), "%s:%d",host, vport);
+                host = thost;
+            }
+        } // else nothing to alter port-wise.
         int url_sz = strlen(url) + 32 + Config.appendDomainLen +
                      strlen(host);
         http->uri = (char *)xcalloc(url_sz, 1);
@@ -1884,24 +1901,22 @@ prepareAcceleratedURL(ConnStateData * conn, ClientHttpRequest *http, char *url,
                                "https" : conn->port->protocol;
         snprintf(http->uri, url_sz, "%s://%s%s", protocol, host, url);
         debugs(33, 5, "ACCEL VHOST REWRITE: '" << http->uri << "'");
-    } else if (conn->port->defaultsite) {
+    } else if (conn->port->defaultsite /* && !vhost */) {
+        debugs(33, 5, "ACCEL DEFAULTSITE REWRITE: defaultsite=" << conn->port->defaultsite << " + vport=" << vport);
         int url_sz = strlen(url) + 32 + Config.appendDomainLen +
                      strlen(conn->port->defaultsite);
         http->uri = (char *)xcalloc(url_sz, 1);
-        snprintf(http->uri, url_sz, "%s://%s%s",
-                 conn->port->protocol, conn->port->defaultsite, url);
+        char vportStr[32];
+        vportStr[0] = '\0';
+        if (vport > 0) {
+            snprintf(vportStr, sizeof(vportStr),":%d",vport);
+        }
+        snprintf(http->uri, url_sz, "%s://%s%s%s",
+                 conn->port->protocol, conn->port->defaultsite, vportStr, url);
         debugs(33, 5, "ACCEL DEFAULTSITE REWRITE: '" << http->uri <<"'");
-    } else if (vport == -1) {
-        /* Put the local socket IP address as the hostname.  */
-        int url_sz = strlen(url) + 32 + Config.appendDomainLen;
-        http->uri = (char *)xcalloc(url_sz, 1);
-        http->getConn()->me.ToHostname(ipbuf,MAX_IPSTRLEN);
-        snprintf(http->uri, url_sz, "%s://%s:%d%s",
-                 http->getConn()->port->protocol,
-                 ipbuf, http->getConn()->me.GetPort(), url);
-        debugs(33, 5, "ACCEL VPORT REWRITE: '" << http->uri << "'");
-    } else if (vport > 0) {
-        /* Put the local socket IP address as the hostname, but static port  */
+    } else if (vport > 0 /* && (!vhost || no Host:) */) {
+        debugs(33, 5, "ACCEL VPORT REWRITE: http_port IP + vport=" << vport);
+        /* Put the local socket IP address as the hostname, with whatever vport we found  */
         int url_sz = strlen(url) + 32 + Config.appendDomainLen;
         http->uri = (char *)xcalloc(url_sz, 1);
         http->getConn()->me.ToHostname(ipbuf,MAX_IPSTRLEN);
@@ -2140,6 +2155,7 @@ parseHttpRequest(ConnStateData *conn, HttpParser *hp, HttpRequestMethod * method
 
 #endif
 
+    debugs(33,5, HERE << "repare absolute URL from " << (csd->transparent()?"intercept":(csd->port->accel ? "accel":"")));
     /* Rewrite the URL in transparent or accelerator mode */
     /* NP: there are several cases to traverse here:
      *  - standard mode (forward proxy)