]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Parser-NG: update response mime parsing
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 28 Sep 2015 07:20:03 +0000 (00:20 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 28 Sep 2015 07:20:03 +0000 (00:20 -0700)
Update the response mime header parse to using the parseHeader()
method previously in HttpRequest.

src/HttpMsg.cc
src/HttpMsg.h
src/HttpRequest.cc
src/HttpRequest.h
src/http.cc

index 5d60656253de36734078571ebe4835ddbdbc70ca..b386244f2830913c5ac4a00b1875890feac5d600 100644 (file)
@@ -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()
index 658e15deab8d98e10fefae77a1b12cf9decb290e..af91ed78df30bd081aafb6fa0c69c0c756c23d87 100644 (file)
@@ -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&);
index c81ec3d83632036d9a31a951f5aa8d5fc5f23d44..4ac3f8925a3397a6a039d8b5251bf2bbb7c07738 100644 (file)
@@ -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)
index 2f26cb100d1b2e59aa9b8b486a5445400dabcd8a..ca7363dbdf5a2de30d42de5c4328a06e4a35652f 100644 (file)
@@ -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
index 912bb467687d34f110973be6f77b3ee0e91e9a80..0396b7ede28c29323cefe0605bb0b824dd11f2c4 100644 (file)
@@ -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;