From: wessels <> Date: Tue, 22 Nov 2005 05:49:04 +0000 (+0000) Subject: Added HttpReply::expectingBody() method to indicate whether or not X-Git-Tag: SQUID_3_0_PRE4~519 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5c09dcb8d666b9b5750b3c92d44878bbb6a767f0;p=thirdparty%2Fsquid.git Added HttpReply::expectingBody() method to indicate whether or not we would usually expect an entity-body in the HTTP response. This was done for ICAP integration. --- diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 6fbe9aca7c..40c3895edf 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.cc,v 1.79 2005/11/07 22:00:38 wessels Exp $ + * $Id: HttpReply.cc,v 1.80 2005/11/21 22:49:04 wessels Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -51,7 +51,6 @@ static http_hdr_type Denied304HeadersArr[] = HDR_OTHER }; - /* module initialization */ void httpReplyInitModule(void) @@ -61,7 +60,6 @@ httpReplyInitModule(void) httpHeaderCalcMask(&Denied304HeadersMask, (const int *) Denied304HeadersArr, countof(Denied304HeadersArr)); } - HttpReply::HttpReply() : HttpMsg(hoReply), date (0), last_modified (0), expires (0), surrogate_control (NULL), content_range (NULL), keep_alive (0), protoPrefix("HTTP/") { init(); @@ -307,7 +305,6 @@ HttpReply::validatorsMatch(HttpReply const * otherRep) const return 1; } - void HttpReply::updateOnNotModified(HttpReply const * freshRep) { @@ -323,7 +320,6 @@ HttpReply::updateOnNotModified(HttpReply const * freshRep) hdrCacheInit(); } - /* internal routines */ time_t @@ -461,3 +457,35 @@ bool HttpReply::parseFirstLine(const char *blk_start, const char *blk_end) { return httpStatusLineParse(&sline, protoPrefix, blk_start, blk_end); } + +/* + * Indicate whether or not we would usually expect an entity-body + * along with this response + */ +bool +HttpReply::expectingBody(method_t req_method, ssize_t& theSize) const +{ + bool expectBody = true; + + if (req_method == METHOD_HEAD) + expectBody = false; + else if (sline.status == HTTP_NO_CONTENT) + expectBody = false; + else if (sline.status == HTTP_NOT_MODIFIED) + expectBody = false; + else if (sline.status < HTTP_OK) + expectBody = false; + else + expectBody = true; + + if (expectBody) { + if (httpHeaderHasListMember(&header, HDR_TRANSFER_ENCODING, "chunked", ',')) + theSize = -1; + else if (content_length >= 0) + theSize = content_length; + else + theSize = -1; + } + + return expectBody; +} diff --git a/src/HttpReply.h b/src/HttpReply.h index 35be53b92b..1970d510dc 100644 --- a/src/HttpReply.h +++ b/src/HttpReply.h @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.h,v 1.13 2005/11/07 22:00:38 wessels Exp $ + * $Id: HttpReply.h,v 1.14 2005/11/21 22:49:04 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -77,6 +77,7 @@ public: bool do_clean; public: + virtual bool expectingBody(method_t, ssize_t&) const; void updateOnNotModified(HttpReply const *other); /* absorb: copy the contents of a new reply to the old one, destroy new one */ void absorb(HttpReply * new_rep);