]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Convert Http1Parser header block to SBuf storage
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 31 Dec 2013 14:33:43 +0000 (06:33 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 31 Dec 2013 14:33:43 +0000 (06:33 -0800)
This does add a data copy for the mime headers block, but allows us to
consume data out of the underlying I/O buffer and parse the block into
SBuf cheaply.

Remove the now useless hdr_start, hdr_end, mimeHeaderBytes_ members.

src/http/Http1Parser.cc
src/http/Http1Parser.h

index 5e36d1f75297524268de25f2f2f01058c749b6ef..c1a4a0b9763254a15fc21157ea3bac4cf0aa3e99 100644 (file)
@@ -15,13 +15,12 @@ Http::Http1Parser::clear()
     bufsiz = 0;
     parseOffset_ = 0;
     req.start = req.end = -1;
-    hdr_start = hdr_end = -1;
     req.m_start = req.m_end = -1;
     req.u_start = req.u_end = -1;
     req.v_start = req.v_end = -1;
     msgProtocol_ = AnyP::ProtocolVersion();
     method_ = NULL;
-    mimeHeaderBytes_ = 0;
+    mimeHeaderBlock_.clear();
 }
 
 void
@@ -341,24 +340,18 @@ Http::Http1Parser::parseRequest()
 
     // stage 3: locate the mime header block
     if (completedState_ == HTTP_PARSE_FIRST) {
-
-        // NP: set these to same value representing 0-byte headers.
-        hdr_start = req.end + 1;
-        hdr_end = hdr_start;
-
         // HTTP/1.x request-line is valid and parsing completed.
         if (msgProtocol_.major == 1) {
             /* NOTE: HTTP/0.9 requests do not have a mime header block.
              *       So the rest of the code will need to deal with '0'-byte headers
              *       (ie, none, so don't try parsing em)
              */
-            if ((mimeHeaderBytes_ = headersEnd(buf+parseOffset_, bufsiz-parseOffset_)) == 0) {
+            int64_t mimeHeaderBytes = 0;
+            if ((mimeHeaderBytes = headersEnd(buf+parseOffset_, bufsiz-parseOffset_)) == 0) {
                 debugs(33, 5, "Incomplete request, waiting for end of headers");
                 return false;
             }
-
-            hdr_start = req.end + 1;
-            hdr_end = parseOffset_ + mimeHeaderBytes_ - 1;
+            mimeHeaderBlock_.assign(&buf[req.end+1], mimeHeaderBytes);
 
         } else
             debugs(33, 3, "Missing HTTP/1.x identifier");
index 803b5b82e889002b7ee35df8eb3f88f04def7d68..d78fad0ec78165522b98ff8e5a0bf337223edc22 100644 (file)
@@ -5,6 +5,7 @@
 #include "http/forward.h"
 #include "http/ProtocolVersion.h"
 #include "http/StatusCode.h"
+#include "SBuf.h"
 
 namespace Http {
 
@@ -57,16 +58,15 @@ public:
 
     /// size in bytes of the message headers including CRLF terminator(s)
     /// but excluding request-line bytes
-    int64_t headerBlockSize() const {return mimeHeaderBytes_;}
+    int64_t headerBlockSize() const {return mimeHeaderBlock_.length();}
 
     /// size in bytes of HTTP message block, includes request-line and mime headers
     /// excludes any body/entity/payload bytes
     /// excludes any garbage prefix before the request-line
     int64_t messageHeaderSize() const {return firstLineSize() + headerBlockSize();}
 
-    /// buffer containing HTTP mime headers
-    // TODO: convert to SBuf
-    const char *rawHeaderBuf() {return buf + hdr_start;}
+    /// buffer containing HTTP mime headers, excluding request or status line.
+    const char *rawHeaderBuf() {return mimeHeaderBlock_.c_str();}
 
     /** Attempt to parse a request.
      * \return true if a valid request was parsed.
@@ -97,10 +97,6 @@ public:
     /// the HTTP method if this is a request method
     const HttpRequestMethodPointer & method() const {return method_;}
 
-    // Offsets for pieces of the MiME Header segment
-    // \deprecated use rawHeaderBuf() and headerBlockSize() instead
-    int hdr_start, hdr_end;
-
     // TODO: Offsets for pieces of the (HTTP reply) Status-Line as per RFC 2616
 
     /** HTTP status code to be used on the invalid-request error page
@@ -124,8 +120,8 @@ private:
     /// what request method has been found on the first line
     HttpRequestMethodPointer method_;
 
-    /// number of bytes in the mime header block
-    int64_t mimeHeaderBytes_;
+    /// buffer holding the mime headers
+    SBuf mimeHeaderBlock_;
 };
 
 } // namespace Http