From: Amos Jeffries Date: Mon, 25 Jul 2011 01:38:40 +0000 (-0600) Subject: Regression fix: vhost and defaultsite causing vport to be ignored X-Git-Tag: SQUID_3_1_15~32^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90216ca634496a29ba20d54036134a8672159d98;p=thirdparty%2Fsquid.git Regression fix: vhost and defaultsite causing vport to be ignored 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. --- diff --git a/src/cf.data.pre b/src/cf.data.pre index 6383ca86ca..95b0af907c 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -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. diff --git a/src/client_side.cc b/src/client_side.cc index c68564159d..a91a12c4bd 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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)