From: Amos Jeffries Date: Sun, 27 Apr 2014 07:59:17 +0000 (-0700) Subject: Bug 1961: pt1: URL handling redesign X-Git-Tag: SQUID_3_5_0_1~261 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4e3f4dc76d5d21fdc0a17c7f04b6e86ca3d1a382;p=thirdparty%2Fsquid.git Bug 1961: pt1: URL handling redesign Replace the HttpMsg::protocol member (only used by HttpRequest) with a class URL member HttpRequest::url. To do this we adjust the class URL scheme_ member to be mutable via the makeScheme() setter, and add a clear() method to reset its internal state. These are necessary for HttpRequest init() and initHTTP() mechanisms, but fiddling with the scheme should be avoided as much as possible. Remove the hack of forcing internal requests to http:// for processing and cache lookup, then to internal:// for FwdState. Instead use the available flags.internal for requests identified to be served by this proxy. Drop the non-standard and now meaningless "internal://" scheme. Add debugging to display what internal indicators are detected and when the internal*() server and CacheManager are used by FwdState. Also document HttpMsg::http_ver which is a copy of the HTTP-Version field in the "on-wire" message syntax. It is unrelated to the socket transport protocol and the URL scheme protocol. --- diff --git a/src/FwdState.cc b/src/FwdState.cc index d3f826376f..3e492e37f6 100644 --- a/src/FwdState.cc +++ b/src/FwdState.cc @@ -321,7 +321,7 @@ FwdState::Start(const Comm::ConnectionPointer &clientConn, StoreEntry *entry, Ht */ if ( Config.accessList.miss && !request->client_addr.isNoAddr() && - request->protocol != AnyP::PROTO_INTERNAL && request->protocol != AnyP::PROTO_CACHE_OBJECT) { + !request->flags.internal && request->url.getScheme() != AnyP::PROTO_CACHE_OBJECT) { /** * Check if this host is allowed to fetch MISSES from us (miss_access). * Intentionally replace the src_addr automatically selected by the checklist code @@ -361,13 +361,16 @@ FwdState::Start(const Comm::ConnectionPointer &clientConn, StoreEntry *entry, Ht return; } - switch (request->protocol) { - - case AnyP::PROTO_INTERNAL: + if (request->flags.internal) { + debugs(17, 2, "calling internalStart() due to request flag"); internalStart(clientConn, request, entry); return; + } + + switch (request->url.getScheme()) { case AnyP::PROTO_CACHE_OBJECT: + debugs(17, 2, "calling CacheManager due to request scheme " << request->url.getScheme()); CacheManager::GetInstance()->Start(clientConn, request, entry); return; @@ -692,7 +695,7 @@ FwdState::connectDone(const Comm::ConnectionPointer &conn, comm_err_t status, in #if USE_OPENSSL if (!request->flags.pinned) { if ((serverConnection()->getPeer() && serverConnection()->getPeer()->use_ssl) || - (!serverConnection()->getPeer() && request->protocol == AnyP::PROTO_HTTPS) || + (!serverConnection()->getPeer() && request->url.getScheme() == AnyP::PROTO_HTTPS) || request->flags.sslPeek) { HttpRequest::Pointer requestPointer = request; @@ -946,7 +949,7 @@ FwdState::dispatch() request->peer_login = NULL; request->peer_domain = NULL; - switch (request->protocol) { + switch (request->url.getScheme()) { #if USE_OPENSSL case AnyP::PROTO_HTTPS: @@ -968,8 +971,6 @@ FwdState::dispatch() case AnyP::PROTO_CACHE_OBJECT: - case AnyP::PROTO_INTERNAL: - case AnyP::PROTO_URN: fatal_dump("Should never get here"); break; diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 3b8ca169b9..352dbb94ff 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -41,7 +41,7 @@ #include "SquidConfig.h" HttpMsg::HttpMsg(http_hdr_owner_type owner): header(owner), - cache_control(NULL), hdr_sz(0), content_length(0), protocol(AnyP::PROTO_NONE), + cache_control(NULL), hdr_sz(0), content_length(0), pstate(psReadyToParseStartLine) {} diff --git a/src/HttpMsg.h b/src/HttpMsg.h index f20ba6838f..bb17b41778 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -67,6 +67,8 @@ public: bool persistent() const; public: + /// HTTP-Version field in the first line of the message. + /// see draft-ietf-httpbis-p1-messaging-26 section 3.1 Http::ProtocolVersion http_ver; HttpHeader header; @@ -80,8 +82,6 @@ public: int64_t content_length; - AnyP::ProtocolType protocol; - HttpMsgParseState pstate; /* the current parsing state */ BodyPipe::Pointer body_pipe; // optional pipeline to receive message body diff --git a/src/HttpReply.cc b/src/HttpReply.cc index a7df80b8a9..024f78d0ca 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -604,7 +604,6 @@ HttpReply::clone() const rep->pstate = pstate; rep->body_pipe = body_pipe; - rep->protocol = protocol; // keep_alive is handled in hdrCacheInit() return rep; } diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index d73f56535f..f015b3a78c 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -82,7 +82,7 @@ void HttpRequest::initHTTP(const HttpRequestMethod& aMethod, AnyP::ProtocolType aProtocol, const char *aUrlpath) { method = aMethod; - protocol = aProtocol; + url.setScheme(aProtocol); urlpath = aUrlpath; } @@ -90,7 +90,7 @@ void HttpRequest::init() { method = Http::METHOD_NONE; - protocol = AnyP::PROTO_NONE; + url.clear(); urlpath = NULL; login[0] = '\0'; host[0] = '\0'; @@ -150,6 +150,7 @@ HttpRequest::clean() safe_free(vary_headers); + url.clear(); urlpath.clean(); header.clean(); @@ -197,7 +198,7 @@ HttpRequest::reset() HttpRequest * HttpRequest::clone() const { - HttpRequest *copy = new HttpRequest(method, protocol, urlpath.termedBuf()); + HttpRequest *copy = new HttpRequest(method, url.getScheme(), urlpath.termedBuf()); // TODO: move common cloning clone to Msg::copyTo() or copy ctor copy->header.append(&header); copy->hdrCacheInit(); @@ -594,7 +595,7 @@ HttpRequest::maybeCacheable() if (!flags.hostVerified && (flags.intercepted || flags.interceptTproxy)) return false; - switch (protocol) { + switch (url.getScheme()) { case AnyP::PROTO_HTTP: case AnyP::PROTO_HTTPS: if (!method.respMaybeCacheable()) diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 65dbf5efd1..0d8e3b057a 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -39,6 +39,7 @@ #include "HttpRequestMethod.h" #include "Notes.h" #include "RequestFlags.h" +#include "URL.h" #if USE_AUTH #include "auth/UserRequest.h" @@ -136,6 +137,9 @@ protected: public: HttpRequestMethod method; + // TODO expand to include all URI parts + URL url; ///< the request URI (scheme only) + char login[MAX_LOGIN_SZ]; private: diff --git a/src/URL.h b/src/URL.h index 5aff09d66c..30f9029785 100644 --- a/src/URL.h +++ b/src/URL.h @@ -45,8 +45,16 @@ public: MEMPROXY_CLASS(URL); URL() : scheme_() {} URL(AnyP::UriScheme const &aScheme) : scheme_(aScheme) {} + + void clear() { + scheme_=AnyP::PROTO_NONE; + } + AnyP::UriScheme const & getScheme() const {return scheme_;} + /// convert the URL scheme to that given + void setScheme(const AnyP::ProtocolType &p) {scheme_=p;} + private: /** \par @@ -68,7 +76,7 @@ private: * In order to make taking any of these routes easy, scheme is private * and immutable, only settable at construction time, */ - AnyP::UriScheme const scheme_; + AnyP::UriScheme scheme_; }; MEMPROXY_CLASS_INLINE(URL); diff --git a/src/acl/Protocol.cc b/src/acl/Protocol.cc index 1fb1bc38fb..893277bdd2 100644 --- a/src/acl/Protocol.cc +++ b/src/acl/Protocol.cc @@ -42,9 +42,9 @@ template class ACLStrategised; int -ACLProtocolStrategy::match (ACLData * &data, ACLFilledChecklist *checklist, ACLFlags &) +ACLProtocolStrategy::match(ACLData * &data, ACLFilledChecklist *checklist, ACLFlags &) { - return data->match (checklist->request->protocol); + return data->match(checklist->request->url.getScheme()); } ACLProtocolStrategy * diff --git a/src/adaptation/ecap/Host.cc b/src/adaptation/ecap/Host.cc index 42f0d9e7dd..7770e3707e 100644 --- a/src/adaptation/ecap/Host.cc +++ b/src/adaptation/ecap/Host.cc @@ -45,7 +45,6 @@ Adaptation::Ecap::Host::Host() libecap::protocolWais.assignHostId(AnyP::PROTO_WAIS); libecap::protocolUrn.assignHostId(AnyP::PROTO_URN); libecap::protocolWhois.assignHostId(AnyP::PROTO_WHOIS); - protocolInternal.assignHostId(AnyP::PROTO_INTERNAL); protocolCacheObj.assignHostId(AnyP::PROTO_CACHE_OBJECT); protocolIcp.assignHostId(AnyP::PROTO_ICP); #if USE_HTCP diff --git a/src/adaptation/ecap/MessageRep.cc b/src/adaptation/ecap/MessageRep.cc index 68bdea9181..bb06ede8a5 100644 --- a/src/adaptation/ecap/MessageRep.cc +++ b/src/adaptation/ecap/MessageRep.cc @@ -158,8 +158,6 @@ Adaptation::Ecap::FirstLineRep::protocol() const #endif case AnyP::PROTO_CACHE_OBJECT: return protocolCacheObj; - case AnyP::PROTO_INTERNAL: - return protocolInternal; case AnyP::PROTO_ICY: return protocolIcy; case AnyP::PROTO_COAP: diff --git a/src/anyp/ProtocolType.h b/src/anyp/ProtocolType.h index a40ac64073..981301681e 100644 --- a/src/anyp/ProtocolType.h +++ b/src/anyp/ProtocolType.h @@ -27,7 +27,6 @@ typedef enum { #endif PROTO_URN, PROTO_WHOIS, - PROTO_INTERNAL, PROTO_ICY, PROTO_UNKNOWN, PROTO_MAX diff --git a/src/carp.cc b/src/carp.cc index 3c1c65a3c7..fd01c2f2c5 100644 --- a/src/carp.cc +++ b/src/carp.cc @@ -191,9 +191,7 @@ carpSelectParent(HttpRequest * request) //this code follows urlCanonical's pattern. // corner cases should use the canonical URL if (tp->options.carp_key.scheme) { - // temporary, until bug 1961 URL handling is fixed. - const AnyP::UriScheme sch(request->protocol); - key.append(sch.c_str()); + key.append(request->url.getScheme().c_str()); if (key.length()) //if the scheme is not empty key.append("://"); } diff --git a/src/cf.data.pre b/src/cf.data.pre index d0edb709e7..0bd1fd0498 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -729,7 +729,7 @@ DOC_START %SRCPORT Client source port %URI Requested URI %DST Requested host - %PROTO Requested protocol + %PROTO Requested URL scheme %PORT Requested port %PATH Requested URL path %METHOD Request method diff --git a/src/client_side.cc b/src/client_side.cc index 416c153029..b42dc70ed5 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -2720,20 +2720,23 @@ clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *c } if (internalCheck(request->urlpath.termedBuf())) { - if (internalHostnameIs(request->GetHost()) && - request->port == getMyPort()) { + if (internalHostnameIs(request->GetHost()) && request->port == getMyPort()) { + debugs(33, 2, "internal URL found: " << request->url.getScheme() << "://" << request->GetHost() << + ':' << request->port); http->flags.internal = true; } else if (Config.onoff.global_internal_static && internalStaticCheck(request->urlpath.termedBuf())) { + debugs(33, 2, "internal URL found: " << request->url.getScheme() << "://" << request->GetHost() << + ':' << request->port << " (global_internal_static on)"); request->SetHost(internalHostname()); request->port = getMyPort(); http->flags.internal = true; - } + } else + debugs(33, 2, "internal URL found: " << request->url.getScheme() << "://" << request->GetHost() << + ':' << request->port << " (not this proxy)"); } - if (http->flags.internal) { - request->protocol = AnyP::PROTO_HTTP; + if (http->flags.internal) request->login[0] = '\0'; - } request->flags.internal = http->flags.internal; setLogUri (http, urlCanonicalClean(request.getRaw())); diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 75e0989c01..c3ba1d153b 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -583,7 +583,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result) */ http->logType = LOG_TCP_CLIENT_REFRESH_MISS; processMiss(); - } else if (r->protocol == AnyP::PROTO_HTTP) { + } else if (r->url.getScheme() == AnyP::PROTO_HTTP) { debugs(88, 3, "validate HIT object? YES."); /* * Object needs to be revalidated @@ -687,10 +687,6 @@ clientReplyContext::processMiss() return; } - /** Check for internal requests. Update Protocol info if so. */ - if (http->flags.internal) - r->protocol = AnyP::PROTO_INTERNAL; - assert(r->clientConnectionManager == http->getConn()); /** Start forwarding to get the new object from network */ diff --git a/src/client_side_request.cc b/src/client_side_request.cc index a09d072bad..a84320a603 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -678,10 +678,10 @@ ClientRequestContext::hostHeaderVerify() // Verify forward-proxy requested URL domain matches the Host: header debugs(85, 3, HERE << "FAIL on validate URL port " << http->request->port << " matches Host: port " << portStr); hostHeaderVerifyFailed("URL port", portStr); - } else if (!portStr && http->request->method != Http::METHOD_CONNECT && http->request->port != urlDefaultPort(http->request->protocol)) { + } else if (!portStr && http->request->method != Http::METHOD_CONNECT && http->request->port != urlDefaultPort(http->request->url.getScheme())) { // Verify forward-proxy requested URL domain matches the Host: header // Special case: we don't have a default-port to check for CONNECT. Assume URL is correct. - debugs(85, 3, HERE << "FAIL on validate URL port " << http->request->port << " matches Host: default port " << urlDefaultPort(http->request->protocol)); + debugs(85, 3, "FAIL on validate URL port " << http->request->port << " matches Host: default port " << urlDefaultPort(http->request->url.getScheme())); hostHeaderVerifyFailed("URL port", "default port"); } else { // Okay no problem. @@ -983,13 +983,13 @@ clientHierarchical(ClientHttpRequest * http) if (request->flags.loopDetected) return 0; - if (request->protocol == AnyP::PROTO_HTTP) + if (request->url.getScheme() == AnyP::PROTO_HTTP) return method.respMaybeCacheable(); - if (request->protocol == AnyP::PROTO_GOPHER) + if (request->url.getScheme() == AnyP::PROTO_GOPHER) return gopherCachable(request); - if (request->protocol == AnyP::PROTO_CACHE_OBJECT) + if (request->url.getScheme() == AnyP::PROTO_CACHE_OBJECT) return 0; return 1; diff --git a/src/errorpage.cc b/src/errorpage.cc index 0b8be4126b..a8dbf22e2d 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -972,7 +972,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion case 'P': if (request) { - p = AnyP::ProtocolType_str[request->protocol]; + p = request->url.getScheme().c_str(); } else if (!building_deny_info_url) { p = "[unknown protocol]"; } diff --git a/src/external_acl.cc b/src/external_acl.cc index 3fc75227a9..6f12473d21 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -1045,7 +1045,7 @@ makeExternalAclKey(ACLFilledChecklist * ch, external_acl_data * acl_data) break; case _external_acl_format::EXT_ACL_PROTO: - str = AnyP::ProtocolType_str[request->protocol]; + str = request->url.getScheme().c_str(); break; case _external_acl_format::EXT_ACL_PORT: diff --git a/src/ftp.cc b/src/ftp.cc index 10f96a1ad9..346021c8b5 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -3732,7 +3732,7 @@ ftpUrlWith2f(HttpRequest * request) { String newbuf = "%2f"; - if (request->protocol != AnyP::PROTO_FTP) + if (request->url.getScheme() != AnyP::PROTO_FTP) return NULL; if ( request->urlpath[0]=='/' ) { diff --git a/src/http.cc b/src/http.cc index f860a4299d..90e5229a0a 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1807,7 +1807,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request, if (!hdr_out->has(HDR_HOST)) { if (request->peer_domain) { hdr_out->putStr(HDR_HOST, request->peer_domain); - } else if (request->port == urlDefaultPort(request->protocol)) { + } else if (request->port == urlDefaultPort(request->url.getScheme())) { /* use port# only if not default */ hdr_out->putStr(HDR_HOST, request->GetHost()); } else { @@ -1865,7 +1865,7 @@ HttpStateData::httpBuildRequestHeader(HttpRequest * request, /* append Front-End-Https */ if (flags.front_end_https) { - if (flags.front_end_https == 1 || request->protocol == AnyP::PROTO_HTTPS) + if (flags.front_end_https == 1 || request->url.getScheme() == AnyP::PROTO_HTTPS) hdr_out->putStr(HDR_FRONT_END_HTTPS, "On"); } @@ -1958,7 +1958,7 @@ copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, co else { /* use port# only if not default */ - if (request->port == urlDefaultPort(request->protocol)) { + if (request->port == urlDefaultPort(request->url.getScheme())) { hdr_out->putStr(HDR_HOST, request->GetHost()); } else { httpHeaderPutStrf(hdr_out, HDR_HOST, "%s:%d", diff --git a/src/internal.cc b/src/internal.cc index a9c51c2008..45d3ae96b8 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -73,6 +73,7 @@ internalStart(const Comm::ConnectionPointer &clientConn, HttpRequest * request, entry->append(msgbuf, strlen(msgbuf)); entry->complete(); } else if (0 == strncmp(upath, "/squid-internal-mgr/", 20)) { + debugs(17, 2, "calling CacheManager due to URL-path /squid-internal-mgr/"); CacheManager::GetInstance()->Start(clientConn, request, entry); } else { debugObj(76, 1, "internalStart: unknown request:\n", diff --git a/src/peer_select.cc b/src/peer_select.cc index 39a1c93d63..433a7234a4 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -691,7 +691,7 @@ peerGetSomeDirect(ps_state * ps) return; /* WAIS is not implemented natively */ - if (ps->request->protocol == AnyP::PROTO_WAIS) + if (ps->request->url.getScheme() == AnyP::PROTO_WAIS) return; peerAddFwdServer(&ps->servers, NULL, HIER_DIRECT); diff --git a/src/tests/testHttpRequest.cc b/src/tests/testHttpRequest.cc index a44fc213f2..7851940244 100644 --- a/src/tests/testHttpRequest.cc +++ b/src/tests/testHttpRequest.cc @@ -43,7 +43,7 @@ testHttpRequest::testCreateFromUrlAndMethod() CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast(aRequest->url.getScheme())); CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url)); xfree(url); @@ -55,7 +55,7 @@ testHttpRequest::testCreateFromUrlAndMethod() CPPUNIT_ASSERT(aRequest->method == Http::METHOD_PUT); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast(aRequest->url.getScheme())); CPPUNIT_ASSERT_EQUAL(String("http://foo/bar"), String(url)); xfree(url); @@ -73,7 +73,7 @@ testHttpRequest::testCreateFromUrlAndMethod() CPPUNIT_ASSERT(aRequest->method == Http::METHOD_CONNECT); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String(""), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, static_cast(aRequest->url.getScheme())); CPPUNIT_ASSERT_EQUAL(String("foo:45"), String(url)); xfree(url); } @@ -93,7 +93,7 @@ testHttpRequest::testCreateFromUrl() CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast(aRequest->url.getScheme())); CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url)); xfree(url); } @@ -116,7 +116,7 @@ testHttpRequest::testIPv6HostColonBug() CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast(aRequest->url.getScheme())); CPPUNIT_ASSERT_EQUAL(String("http://[2000:800::45]/foo"), String(url)); xfree(url); @@ -128,7 +128,7 @@ testHttpRequest::testIPv6HostColonBug() CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast(aRequest->url.getScheme())); CPPUNIT_ASSERT_EQUAL(String("http://[2000:800::45]:90/foo"), String(url)); xfree(url); @@ -140,7 +140,7 @@ testHttpRequest::testIPv6HostColonBug() CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET); CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost())); CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); - CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast(aRequest->url.getScheme())); CPPUNIT_ASSERT_EQUAL(String("http://2000:800::45/foo"), String(url)); xfree(url); } diff --git a/src/url.cc b/src/url.cc index cc39da3d78..c7979cd0aa 100644 --- a/src/url.cc +++ b/src/url.cc @@ -146,9 +146,6 @@ urlParseProtocol(const char *b, const char *e) if (strncasecmp(b, "whois", len) == 0) return AnyP::PROTO_WHOIS; - if (strncasecmp(b, "internal", len) == 0) - return AnyP::PROTO_INTERNAL; - return AnyP::PROTO_NONE; } @@ -179,8 +176,6 @@ urlDefaultPort(AnyP::ProtocolType p) return 210; case AnyP::PROTO_CACHE_OBJECT: - - case AnyP::PROTO_INTERNAL: return CACHE_HTTP_PORT; case AnyP::PROTO_WHOIS: @@ -503,7 +498,7 @@ urlCanonical(HttpRequest * request) if (request->canonical) return request->canonical; - if (request->protocol == AnyP::PROTO_URN) { + if (request->url.getScheme() == AnyP::PROTO_URN) { snprintf(urlbuf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(request->urlpath)); } else { @@ -517,12 +512,11 @@ urlCanonical(HttpRequest * request) { portbuf[0] = '\0'; - if (request->port != urlDefaultPort(request->protocol)) + if (request->port != urlDefaultPort(request->url.getScheme())) 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->url.getScheme().c_str(), request->login, *request->login ? "@" : null_string, request->GetHost(), @@ -547,7 +541,7 @@ urlCanonicalClean(const HttpRequest * request) LOCAL_ARRAY(char, loginbuf, MAX_LOGIN_SZ + 1); char *t; - if (request->protocol == AnyP::PROTO_URN) { + if (request->url.getScheme() == AnyP::PROTO_URN) { snprintf(buf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(request->urlpath)); } else { @@ -561,7 +555,7 @@ urlCanonicalClean(const HttpRequest * request) { portbuf[0] = '\0'; - if (request->port != urlDefaultPort(request->protocol)) + if (request->port != urlDefaultPort(request->url.getScheme())) snprintf(portbuf, 32, ":%d", request->port); loginbuf[0] = '\0'; @@ -575,9 +569,8 @@ urlCanonicalClean(const HttpRequest * request) 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(), + request->url.getScheme().c_str(), loginbuf, request->GetHost(), portbuf, @@ -667,7 +660,7 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) char *urlbuf = (char *)xmalloc(MAX_URL * sizeof(char)); - if (req->protocol == AnyP::PROTO_URN) { + if (req->url.getScheme() == AnyP::PROTO_URN) { snprintf(urlbuf, MAX_URL, "urn:" SQUIDSTRINGPH, SQUIDSTRINGPRINT(req->urlpath)); return (urlbuf); @@ -675,10 +668,9 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) size_t urllen; - const AnyP::UriScheme sch = req->protocol; // temporary, until bug 1961 URL handling is fixed. - if (req->port != urlDefaultPort(req->protocol)) { + if (req->port != urlDefaultPort(req->url.getScheme())) { urllen = snprintf(urlbuf, MAX_URL, "%s://%s%s%s:%d", - sch.c_str(), + req->url.getScheme().c_str(), req->login, *req->login ? "@" : null_string, req->GetHost(), @@ -686,7 +678,7 @@ urlMakeAbsolute(const HttpRequest * req, const char *relUrl) ); } else { urllen = snprintf(urlbuf, MAX_URL, "%s://%s%s%s", - sch.c_str(), + req->url.getScheme().c_str(), req->login, *req->login ? "@" : null_string, req->GetHost() @@ -844,7 +836,7 @@ urlCheckRequest(const HttpRequest * r) return 1; /* does method match the protocol? */ - switch (r->protocol) { + switch (r->url.getScheme()) { case AnyP::PROTO_URN: