From: Amos Jeffries Date: Wed, 5 Nov 2014 10:18:15 +0000 (-0800) Subject: Merge from trunk rev.13687 X-Git-Tag: merge-candidate-3-v1~506^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=de95413f57b25f362022b41a4df024e27393a932;p=thirdparty%2Fsquid.git Merge from trunk rev.13687 --- de95413f57b25f362022b41a4df024e27393a932 diff --cc src/acl/MethodData.h index 5c6aff2eef,5bba166cf2..a3c02dcafb --- a/src/acl/MethodData.h +++ b/src/acl/MethodData.h @@@ -11,16 -11,14 +11,14 @@@ #include "acl/Acl.h" #include "acl/Data.h" - #include "CbDataList.h" + #include "base/CbDataList.h" -#include "HttpRequestMethod.h" +#include "http/RequestMethod.h" - /// \ingroup ACLAPI class ACLMethodData : public ACLData { - - public: MEMPROXY_CLASS(ACLMethodData); + public: ACLMethodData(); ACLMethodData(ACLMethodData const &); ACLMethodData &operator= (ACLMethodData const &); diff --cc src/client_side.cc index 82b17ea58f,22a08b5fdc..34a77c01ec --- a/src/client_side.cc +++ b/src/client_side.cc @@@ -2075,15 -2052,14 +2075,13 @@@ prepareAcceleratedURL(ConnStateData * c host = thost; } } // else nothing to alter port-wise. - int url_sz = strlen(url) + 32 + Config.appendDomainLen + - strlen(host); + const int url_sz = hp->requestUri().length() + 32 + Config.appendDomainLen + strlen(host); http->uri = (char *)xcalloc(url_sz, 1); - const char *protocol = switchedToHttps ? - "https" : AnyP::UriScheme(conn->port->transport.protocol).c_str(); - snprintf(http->uri, url_sz, "%s://%s" SQUIDSBUFPH, protocol, host, SQUIDSBUFPRINT(url)); - snprintf(http->uri, url_sz, "%s://%s%s", AnyP::UriScheme(conn->transferProtocol.protocol).c_str(), host, url); - debugs(33, 5, "ACCEL VHOST REWRITE: '" << http->uri << "'"); ++ snprintf(http->uri, url_sz, "%s://%s" SQUIDSBUFPH, AnyP::UriScheme(conn->transferProtocol.protocol).c_str(), host, SQUIDSBUFPRINT(url)); + debugs(33, 5, "ACCEL VHOST REWRITE: " << http->uri); } 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 + + const int url_sz = hp->requestUri().length() + 32 + Config.appendDomainLen + strlen(conn->port->defaultsite); http->uri = (char *)xcalloc(url_sz, 1); char vportStr[32]; @@@ -2091,19 -2067,19 +2089,19 @@@ if (vport > 0) { snprintf(vportStr, sizeof(vportStr),":%d",vport); } - snprintf(http->uri, url_sz, "%s://%s%s%s", - AnyP::UriScheme(conn->transferProtocol.protocol).c_str(), conn->port->defaultsite, vportStr, url); - debugs(33, 5, "ACCEL DEFAULTSITE REWRITE: '" << http->uri <<"'"); + snprintf(http->uri, url_sz, "%s://%s%s" SQUIDSBUFPH, - AnyP::UriScheme(conn->port->transport.protocol).c_str(), conn->port->defaultsite, vportStr, SQUIDSBUFPRINT(url)); ++ AnyP::UriScheme(conn->transferProtocol.protocol).c_str(), conn->port->defaultsite, vportStr, SQUIDSBUFPRINT(url)); + debugs(33, 5, "ACCEL DEFAULTSITE REWRITE: " << http->uri); } else if (vport > 0 /* && (!vhost || no Host:) */) { debugs(33, 5, "ACCEL VPORT REWRITE: *_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; + const int url_sz = hp->requestUri().length() + 32 + Config.appendDomainLen; http->uri = (char *)xcalloc(url_sz, 1); http->getConn()->clientConnection->local.toHostStr(ipbuf,MAX_IPSTRLEN); - snprintf(http->uri, url_sz, "%s://%s:%d%s", + snprintf(http->uri, url_sz, "%s://%s:%d" SQUIDSBUFPH, - AnyP::UriScheme(conn->port->transport.protocol).c_str(), + AnyP::UriScheme(conn->transferProtocol.protocol).c_str(), - ipbuf, vport, url); - debugs(33, 5, "ACCEL VPORT REWRITE: '" << http->uri << "'"); + ipbuf, vport, SQUIDSBUFPRINT(url)); + debugs(33, 5, "ACCEL VPORT REWRITE: " << http->uri); } } @@@ -2116,23 -2094,21 +2114,23 @@@ prepareTransparentURL(ConnStateData * c /* BUG: Squid cannot deal with '*' URLs (RFC2616 5.1.2) */ - if ((host = mime_get_header(req_hdr, "Host")) != NULL) { - int url_sz = strlen(url) + 32 + Config.appendDomainLen + + if (const char *host = hp->getHeaderField("Host")) { + const int url_sz = hp->requestUri().length() + 32 + Config.appendDomainLen + strlen(host); http->uri = (char *)xcalloc(url_sz, 1); - snprintf(http->uri, url_sz, "%s://%s%s", AnyP::UriScheme(conn->transferProtocol.protocol).c_str(), host, url); - debugs(33, 5, "TRANSPARENT HOST REWRITE: '" << http->uri <<"'"); + snprintf(http->uri, url_sz, "%s://%s" SQUIDSBUFPH, - AnyP::UriScheme(conn->port->transport.protocol).c_str(), host, SQUIDSBUFPRINT(hp->requestUri())); ++ AnyP::UriScheme(conn->transferProtocol.protocol).c_str(), host, SQUIDSBUFPRINT(hp->requestUri())); + debugs(33, 5, "TRANSPARENT HOST REWRITE: " << http->uri); } else { /* Put the local socket IP address as the hostname. */ - int url_sz = strlen(url) + 32 + Config.appendDomainLen; + const int url_sz = hp->requestUri().length() + 32 + Config.appendDomainLen; http->uri = (char *)xcalloc(url_sz, 1); + static char ipbuf[MAX_IPSTRLEN]; http->getConn()->clientConnection->local.toHostStr(ipbuf,MAX_IPSTRLEN); - snprintf(http->uri, url_sz, "%s://%s:%d%s", + snprintf(http->uri, url_sz, "%s://%s:%d" SQUIDSBUFPH, - AnyP::UriScheme(http->getConn()->port->transport.protocol).c_str(), + AnyP::UriScheme(http->getConn()->transferProtocol.protocol).c_str(), - ipbuf, http->getConn()->clientConnection->local.port(), url); - debugs(33, 5, "TRANSPARENT REWRITE: '" << http->uri << "'"); + ipbuf, http->getConn()->clientConnection->local.port(), SQUIDSBUFPRINT(hp->requestUri())); + debugs(33, 5, "TRANSPARENT REWRITE: " << http->uri); } } @@@ -2150,39 -2126,83 +2148,39 @@@ * a ClientSocketContext structure on success or failure. */ ClientSocketContext * -parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_p, Http::ProtocolVersion *http_ver) +parseHttpRequest(ConnStateData *csd, const Http1::RequestParserPointer &hp) { - char *req_hdr = NULL; - char *end; - size_t req_sz; - ClientHttpRequest *http; - ClientSocketContext *result; - StoreIOBuffer tempBuffer; - int r; - - /* pre-set these values to make aborting simpler */ - *method_p = Http::METHOD_NONE; - - /* NP: don't be tempted to move this down or remove again. - * It's the only DDoS protection old-String has against long URL */ - if ( hp->bufsiz <= 0) { - debugs(33, 5, "Incomplete request, waiting for end of request line"); - return NULL; - } else if ( (size_t)hp->bufsiz >= Config.maxRequestHeaderSize && headersEnd(hp->buf, Config.maxRequestHeaderSize) == 0) { - debugs(33, 5, "parseHttpRequest: Too large request"); - hp->request_parse_status = Http::scHeaderTooLarge; - return csd->abortRequestParsing("error:request-too-large"); - } - - /* Attempt to parse the first line; this'll define the method, url, version and header begin */ - r = HttpParserParseReqLine(hp); - - if (r == 0) { - debugs(33, 5, "Incomplete request, waiting for end of request line"); - return NULL; - } - - if (r == -1) { - return csd->abortRequestParsing("error:invalid-request"); - } + /* Attempt to parse the first line; this will define where the method, url, version and header begin */ + { + const bool parsedOk = hp->parse(csd->in.buf); - /* Request line is valid here .. */ - *http_ver = Http::ProtocolVersion(hp->req.v_maj, hp->req.v_min); + // sync the buffers after parsing. + csd->in.buf = hp->remaining(); - /* This call scans the entire request, not just the headers */ - if (hp->req.v_maj > 0) { - if ((req_sz = headersEnd(hp->buf, hp->bufsiz)) == 0) { - debugs(33, 5, "Incomplete request, waiting for end of headers"); + if (hp->needsMoreData()) { + debugs(33, 5, "Incomplete request, waiting for end of request line"); return NULL; } - } else { - debugs(33, 3, "parseHttpRequest: Missing HTTP identifier"); - req_sz = HttpParserReqSz(hp); - } - - /* We know the whole request is in hp->buf now */ - - assert(req_sz <= (size_t) hp->bufsiz); - /* Will the following be true with HTTP/0.9 requests? probably not .. */ - /* So the rest of the code will need to deal with '0'-byte headers (ie, none, so don't try parsing em) */ - assert(req_sz > 0); + if (!parsedOk) { + if (hp->request_parse_status == Http::scRequestHeaderFieldsTooLarge || hp->request_parse_status == Http::scUriTooLong) + return csd->abortRequestParsing("error:request-too-large"); - hp->hdr_end = req_sz - 1; - - hp->hdr_start = hp->req.end + 1; - - /* Enforce max_request_size */ - if (req_sz >= Config.maxRequestHeaderSize) { - debugs(33, 5, "parseHttpRequest: Too large request"); - hp->request_parse_status = Http::scHeaderTooLarge; - return csd->abortRequestParsing("error:request-too-large"); + return csd->abortRequestParsing("error:invalid-request"); + } } - /* Set method_p */ - *method_p = HttpRequestMethod(&hp->buf[hp->req.m_start], &hp->buf[hp->req.m_end]+1); + /* We know the whole request is in parser now */ + debugs(11, 2, "HTTP Client " << csd->clientConnection); + debugs(11, 2, "HTTP Client REQUEST:\n---------\n" << + hp->method() << " " << hp->requestUri() << " " << hp->messageProtocol() << "\n" << + hp->mimeHeader() << + "\n----------"); /* deny CONNECT via accelerated ports */ - if (*method_p == Http::METHOD_CONNECT && csd->port != NULL && csd->port->flags.accelSurrogate) { + if (hp->method() == Http::METHOD_CONNECT && csd->port != NULL && csd->port->flags.accelSurrogate) { - debugs(33, DBG_IMPORTANT, "WARNING: CONNECT method received on " << csd->port->transport.protocol << " Accelerator port " << csd->port->s.port()); + debugs(33, DBG_IMPORTANT, "WARNING: CONNECT method received on " << csd->transferProtocol << " Accelerator port " << csd->port->s.port()); - /* XXX need a way to say "this many character length string" */ - debugs(33, DBG_IMPORTANT, "WARNING: for request: " << hp->buf); + debugs(33, DBG_IMPORTANT, "WARNING: for request: " << hp->method() << " " << hp->requestUri() << " " << hp->messageProtocol()); hp->request_parse_status = Http::scMethodNotAllowed; return csd->abortRequestParsing("error:method-not-allowed"); } diff --cc src/htcp.cc index 3e356eee2a,129a3aaa45..faa2f6cc29 --- a/src/htcp.cc +++ b/src/htcp.cc @@@ -159,17 -157,10 +158,15 @@@ private htcpDataHeader *dhdr; }; - MEMPROXY_CLASS_INLINE(htcpSpecifier); - struct _htcpDetail { char *resp_hdrs; + size_t respHdrsSz; + char *entity_hdrs; + size_t entityHdrsSz; + char *cache_hdrs; + size_t cacheHdrsSz; }; struct _htcpStuff {