From: Amos Jeffries Date: Mon, 28 Sep 2015 07:20:03 +0000 (-0700) Subject: Parser-NG: update response mime parsing X-Git-Tag: SQUID_4_0_1~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=af2980f3e8eb15f78d532a41c65e1299cc84e3a9;p=thirdparty%2Fsquid.git Parser-NG: update response mime parsing Update the response mime header parse to using the parseHeader() method previously in HttpRequest. --- diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 5d60656253..b386244f28 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -10,6 +10,7 @@ #include "squid.h" #include "Debug.h" +#include "http/one/Parser.h" #include "HttpHeaderTools.h" #include "HttpMsg.h" #include "MemBuf.h" @@ -281,6 +282,27 @@ HttpMsg::httpMsgParseStep(const char *buf, int len, int atEnd) return 1; } +bool +HttpMsg::parseHeader(Http1::Parser &hp) +{ + // HTTP/1 message contains "zero or more header fields" + // zero does not need parsing + if (!hp.headerBlockSize()) { + pstate = psParsed; + return true; + } + + // XXX: c_str() reallocates. performance regression. + if (header.parse(hp.mimeHeader().c_str(), hp.headerBlockSize())) { + pstate = psParsed; + hdrCacheInit(); + return true; + } + + pstate = psError; + return false; +} + /* handy: resets and returns -1 */ int HttpMsg::httpMsgParseError() diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 658e15deab..af91ed78df 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -76,6 +76,9 @@ public: virtual int httpMsgParseError(); + // Parser-NG transitional parsing of mime headers + bool parseHeader(Http1::Parser &); // TODO move this function to the parser + virtual bool expectingBody(const HttpRequestMethod&, int64_t&) const = 0; void firstLineBuf(MemBuf&); diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index c81ec3d836..4ac3f8925a 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -335,23 +335,6 @@ HttpRequest::parseFirstLine(const char *start, const char *end) return true; } -bool -HttpRequest::parseHeader(Http1::RequestParser &hp) -{ - // HTTP/1 message contains "zero or more header fields" - // zero does not need parsing - if (!hp.headerBlockSize()) - return true; - - // XXX: c_str() reallocates. performance regression. - const bool result = header.parse(hp.mimeHeader().c_str(), hp.headerBlockSize()); - - if (result) - hdrCacheInit(); - - return result; -} - /* swaps out request using httpRequestPack */ void HttpRequest::swapOut(StoreEntry * e) diff --git a/src/HttpRequest.h b/src/HttpRequest.h index 2f26cb100d..ca7363dbdf 100644 --- a/src/HttpRequest.h +++ b/src/HttpRequest.h @@ -181,8 +181,6 @@ public: bool parseFirstLine(const char *start, const char *end); - bool parseHeader(Http1::RequestParser &hp); // TODO move this function to the parser - virtual bool expectingBody(const HttpRequestMethod& unused, int64_t&) const; bool bodyNibbled() const; // the request has a [partially] consumed body diff --git a/src/http.cc b/src/http.cc index 912bb46768..0396b7ede2 100644 --- a/src/http.cc +++ b/src/http.cc @@ -758,8 +758,7 @@ HttpStateData::processReplyHeader() newrep->sline.version.minor = hp->messageProtocol().minor; // parse headers - newrep->pstate = psReadyToParseHeaders; - if (newrep->httpMsgParseStep(hp->mimeHeader().rawContent(), hp->mimeHeader().length(), true) < 0) { + if (!newrep->parseHeader(*hp)) { // XXX: when Http::ProtocolVersion is a function, remove this hack. just set with messageProtocol() newrep->sline.set(Http::ProtocolVersion(), Http::scInvalidHeader); newrep->sline.version.protocol = hp->messageProtocol().protocol;