From: Amos Jeffries Date: Sun, 22 Dec 2013 16:21:04 +0000 (-0800) Subject: Inline and document the HTTP message size macros X-Git-Tag: merge-candidate-3-v1~506^2~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7e1d6c48ac7cdf1bc97fbdcc59b0b95db4c1e2af;p=thirdparty%2Fsquid.git Inline and document the HTTP message size macros --- diff --git a/src/HttpParser.h b/src/HttpParser.h index ded60cf505..fe09f8434c 100644 --- a/src/HttpParser.h +++ b/src/HttpParser.h @@ -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 */ diff --git a/src/client_side.cc b/src/client_side.cc index 77229a3dd7..210476459b 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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(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);