------------------------------------------------------------ revno: 13377 revision-id: squid3@treenet.co.nz-20140423142804-t7v12ygiquifa70v parent: squid3@treenet.co.nz-20140423135213-3qdakgbi1hkbm1xa committer: Amos Jeffries branch nick: trunk timestamp: Wed 2014-04-23 07:28:04 -0700 message: Polish: update urlCanonical to switch instead of if-else This paves the way fro adding other method dependent canonical URI. Such as the * URI for TRACE and OPTIONS ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20140423142804-t7v12ygiquifa70v # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: ea735e2ededb19d648c9255a1588850b5d3f67dc # timestamp: 2014-04-23 14:54:26 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20140423135213-\ # 3qdakgbi1hkbm1xa # # Begin patch === modified file 'src/url.cc' --- src/url.cc 2014-03-30 12:00:34 +0000 +++ src/url.cc 2014-04-23 14:28:04 +0000 @@ -506,22 +506,30 @@ if (request->protocol == AnyP::PROTO_URN) { snprintf(urlbuf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(request->urlpath)); - } else if (request->method.id() == Http::METHOD_CONNECT) { - snprintf(urlbuf, MAX_URL, "%s:%d", request->GetHost(), request->port); } else { - portbuf[0] = '\0'; - - if (request->port != urlDefaultPort(request->protocol)) - snprintf(portbuf, 32, ":%d", request->port); - - const AnyP::UriScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. - snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s" SQUIDSTRINGPH, - sch.c_str(), - request->login, - *request->login ? "@" : null_string, - request->GetHost(), - portbuf, - SQUIDSTRINGPRINT(request->urlpath)); + switch (request->method.id()) { + + case Http::METHOD_CONNECT: + snprintf(urlbuf, MAX_URL, "%s:%d", request->GetHost(), request->port); + break; + + default: + { + portbuf[0] = '\0'; + + if (request->port != urlDefaultPort(request->protocol)) + snprintf(portbuf, 32, ":%d", request->port); + + const AnyP::UriScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. + snprintf(urlbuf, MAX_URL, "%s://%s%s%s%s" SQUIDSTRINGPH, + sch.c_str(), + request->login, + *request->login ? "@" : null_string, + request->GetHost(), + portbuf, + SQUIDSTRINGPRINT(request->urlpath)); + } + } } return (request->canonical = xstrdup(urlbuf)); @@ -542,39 +550,45 @@ if (request->protocol == AnyP::PROTO_URN) { snprintf(buf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(request->urlpath)); - } else if (request->method.id() == Http::METHOD_CONNECT) { - snprintf(buf, MAX_URL, "%s:%d", request->GetHost(), request->port); } else { - portbuf[0] = '\0'; - - if (request->port != urlDefaultPort(request->protocol)) - snprintf(portbuf, 32, ":%d", request->port); - - loginbuf[0] = '\0'; - - if ((int) strlen(request->login) > 0) { - strcpy(loginbuf, request->login); - - if ((t = strchr(loginbuf, ':'))) - *t = '\0'; - - strcat(loginbuf, "@"); + switch (request->method.id()) { + + case Http::METHOD_CONNECT: + snprintf(urlbuf, MAX_URL, "%s:%d", request->GetHost(), request->port); + break; + + default: + { + portbuf[0] = '\0'; + + if (request->port != urlDefaultPort(request->protocol)) + snprintf(portbuf, 32, ":%d", request->port); + + loginbuf[0] = '\0'; + + if ((int) strlen(request->login) > 0) { + strcpy(loginbuf, request->login); + + if ((t = strchr(loginbuf, ':'))) + *t = '\0'; + + strcat(loginbuf, "@"); + } + + const AnyP::UriScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. + snprintf(buf, MAX_URL, "%s://%s%s%s" SQUIDSTRINGPH, + sch.c_str(), + loginbuf, + request->GetHost(), + portbuf, + SQUIDSTRINGPRINT(request->urlpath)); + + // strip arguments AFTER a question-mark + if (Config.onoff.strip_query_terms) + if ((t = strchr(buf, '?'))) + *(++t) = '\0'; + } } - - const AnyP::UriScheme sch = request->protocol; // temporary, until bug 1961 URL handling is fixed. - snprintf(buf, MAX_URL, "%s://%s%s%s" SQUIDSTRINGPH, - sch.c_str(), - loginbuf, - request->GetHost(), - portbuf, - SQUIDSTRINGPRINT(request->urlpath)); - /* - * strip arguments AFTER a question-mark - */ - - if (Config.onoff.strip_query_terms) - if ((t = strchr(buf, '?'))) - *(++t) = '\0'; } if (stringHasCntl(buf))