]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Inline and document the HTTP message size macros
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 22 Dec 2013 16:21:04 +0000 (08:21 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 22 Dec 2013 16:21:04 +0000 (08:21 -0800)
src/HttpParser.h
src/client_side.cc

index ded60cf5050930ab128977496bc153900110f1d6..fe09f8434cb0b59bb0e31fe10d96bce604ba0351 100644 (file)
@@ -43,6 +43,22 @@ public:
     // TODO: parse more than just the request-line
     bool isDone() const {return completedState_==HTTP_PARSE_FIRST;}
 
+    /// size in bytes of the first line (request-line)
+    /// including CRLF terminator
+    int64_t firstLineSize() const {return req.end - req.start + 1;}
+
+    /// size in bytes of the message headers including CRLF terminator
+    /// but excluding request-line bytes
+    int64_t headerBlockSize() const {return hdr_end - hdr_start + 1;}
+
+    /// size in bytes of HTTP message block, includes request-line and mime headers
+    /// excludes any body/entity/payload bytes
+    int64_t messageHeaderSize() const {return hdr_end - req.start + 1;}
+
+    /// buffer containing HTTP mime headers
+    // convert to SBuf
+    const char *rawHeaderBuf() {return buf + hdr_start;}
+
     /**
      * Attempt to parse the first line of a new request message.
      *
@@ -94,9 +110,4 @@ private:
 // Legacy functions
 int HttpParserParseReqLine(HttpParser *hp);
 
-#define HttpParserReqSz(hp)     ( (hp)->req.end - (hp)->req.start + 1 )
-#define HttpParserHdrSz(hp)     ( (hp)->hdr_end - (hp)->hdr_start + 1 )
-#define HttpParserHdrBuf(hp)    ( (hp)->buf + (hp)->hdr_start )
-#define HttpParserRequestLen(hp)        ( (hp)->hdr_end - (hp)->req.start + 1 )
-
 #endif /*  _SQUID_SRC_HTTPPARSER_H */
index 77229a3dd7ede4c3c0450d87411a6f39e36baba7..210476459be06148f7dc8f1762b7b13944722833 100644 (file)
@@ -2258,7 +2258,7 @@ parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_
         }
     } else {
         debugs(33, 3, "parseHttpRequest: Missing HTTP identifier");
-        req_sz = HttpParserReqSz(hp);
+        req_sz = hp->firstLineSize();
     }
 
     /* We know the whole request is in hp->buf now */
@@ -2313,13 +2313,13 @@ parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_
     debugs(33, 3, "parseHttpRequest: end = {" << end << "}");
 
     debugs(33, 3, "parseHttpRequest: prefix_sz = " <<
-           (int) HttpParserRequestLen(hp) << ", req_line_sz = " <<
-           HttpParserReqSz(hp));
+           hp->messageHeaderSize() << ", request-line-size=" <<
+           hp->firstLineSize());
 
     /* Ok, all headers are received */
     http = new ClientHttpRequest(csd);
 
-    http->req_sz = HttpParserRequestLen(hp);
+    http->req_sz = hp->messageHeaderSize();
     result = ClientSocketContextNew(csd->clientConnection, http);
     tempBuffer.data = result->reqbuf;
     tempBuffer.length = HTTP_REQBUF_SZ;
@@ -2697,14 +2697,14 @@ clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *c
             (http_ver.major > 1) ) {
 
         clientStreamNode *node = context->getClientReplyContext();
-        debugs(33, 5, "Unsupported HTTP version discovered. :\n" << HttpParserHdrBuf(hp));
+        debugs(33, 5, "Unsupported HTTP version discovered. :\n" << hp->rawHeaderBuf());
         conn->quitAfterError(request.getRaw());
         // setLogUri should called before repContext->setReplyToError
         setLogUri(http, http->uri,  true);
         clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
         assert (repContext);
         repContext->setReplyToError(ERR_UNSUP_HTTPVERSION, Http::scHttpVersionNotSupported, method, http->uri,
-                                    conn->clientConnection->remote, NULL, HttpParserHdrBuf(hp), NULL);
+                                    conn->clientConnection->remote, NULL, hp->rawHeaderBuf(), NULL);
         assert(context->http->out.offset == 0);
         context->pullData();
         goto finish;
@@ -2713,9 +2713,9 @@ clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *c
     /* compile headers */
     /* we should skip request line! */
     /* XXX should actually know the damned buffer size here */
-    if (http_ver.major >= 1 && !request->parseHeader(HttpParserHdrBuf(hp), HttpParserHdrSz(hp))) {
+    if (http_ver.major >= 1 && !request->parseHeader(hp->rawHeaderBuf(), hp->headerBlockSize())) {
         clientStreamNode *node = context->getClientReplyContext();
-        debugs(33, 5, "Failed to parse request headers:\n" << HttpParserHdrBuf(hp));
+        debugs(33, 5, "Failed to parse request headers:\n" << hp->rawHeaderBuf());
         conn->quitAfterError(request.getRaw());
         // setLogUri should called before repContext->setReplyToError
         setLogUri(http, http->uri,  true);