From: Amos Jeffries Date: Tue, 31 Dec 2013 14:33:43 +0000 (-0800) Subject: Convert Http1Parser header block to SBuf storage X-Git-Tag: merge-candidate-3-v1~506^2~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb1bd364dee8c99f3e41182a9a5d8074ef127cf8;p=thirdparty%2Fsquid.git Convert Http1Parser header block to SBuf storage 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. --- diff --git a/src/http/Http1Parser.cc b/src/http/Http1Parser.cc index 5e36d1f752..c1a4a0b976 100644 --- a/src/http/Http1Parser.cc +++ b/src/http/Http1Parser.cc @@ -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"); diff --git a/src/http/Http1Parser.h b/src/http/Http1Parser.h index 803b5b82e8..d78fad0ec7 100644 --- a/src/http/Http1Parser.h +++ b/src/http/Http1Parser.h @@ -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