--------------------- PatchSet 1904 Date: 2005/09/29 22:56:59 Author: dwsquid Branch: squid3-icap Tag: (none) Log: Added an expectingBody() method. Return type is boolean. theSize is a return-value parameter that indicates the expected body size if the the return value is true. Members: src/HttpMsg.h:1.1.2.4->1.1.2.5 src/HttpReply.cc:1.21.4.9->1.21.4.10 src/HttpReply.h:1.8.10.8->1.8.10.9 src/HttpRequest.cc:1.16.4.7->1.16.4.8 src/HttpRequest.h:1.13.4.5->1.13.4.6 Index: squid3/src/HttpMsg.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/HttpMsg.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid3/src/HttpMsg.h 18 Sep 2005 04:12:42 -0000 1.1.2.4 +++ squid3/src/HttpMsg.h 29 Sep 2005 22:56:59 -0000 1.1.2.5 @@ -1,6 +1,6 @@ /* - * $Id: HttpMsg.h,v 1.1.2.4 2005/09/18 04:12:42 dwsquid Exp $ + * $Id: HttpMsg.h,v 1.1.2.5 2005/09/29 22:56:59 dwsquid Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -72,6 +72,7 @@ bool parse(MemBuf *buf, bool eol, http_status *error); int httpMsgParseStep(const char *buf, int atEnd); int httpMsgParseError(); + virtual bool expectingBody(method_t, ssize_t&) = 0; protected: Index: squid3/src/HttpReply.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/HttpReply.cc,v retrieving revision 1.21.4.9 retrieving revision 1.21.4.10 diff -u -r1.21.4.9 -r1.21.4.10 --- squid3/src/HttpReply.cc 18 Sep 2005 03:42:58 -0000 1.21.4.9 +++ squid3/src/HttpReply.cc 29 Sep 2005 22:56:59 -0000 1.21.4.10 @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.cc,v 1.21.4.9 2005/09/18 03:42:58 dwsquid Exp $ + * $Id: HttpReply.cc,v 1.21.4.10 2005/09/29 22:56:59 dwsquid Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -517,3 +517,35 @@ { 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) +{ + 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; +} Index: squid3/src/HttpReply.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/HttpReply.h,v retrieving revision 1.8.10.8 retrieving revision 1.8.10.9 diff -u -r1.8.10.8 -r1.8.10.9 --- squid3/src/HttpReply.h 16 Sep 2005 15:35:36 -0000 1.8.10.8 +++ squid3/src/HttpReply.h 29 Sep 2005 22:56:59 -0000 1.8.10.9 @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.h,v 1.8.10.8 2005/09/16 15:35:36 dwsquid Exp $ + * $Id: HttpReply.h,v 1.8.10.9 2005/09/29 22:56:59 dwsquid Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -109,6 +109,7 @@ public: void httpReplyUpdateOnNotModified(HttpReply const *other); + virtual bool expectingBody(method_t, ssize_t&); protected: virtual void packFirstLineInto(Packer * p, bool) const; Index: squid3/src/HttpRequest.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/HttpRequest.cc,v retrieving revision 1.16.4.7 retrieving revision 1.16.4.8 diff -u -r1.16.4.7 -r1.16.4.8 --- squid3/src/HttpRequest.cc 21 Sep 2005 15:10:44 -0000 1.16.4.7 +++ squid3/src/HttpRequest.cc 29 Sep 2005 22:56:59 -0000 1.16.4.8 @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.cc,v 1.16.4.7 2005/09/21 15:10:44 dwsquid Exp $ + * $Id: HttpRequest.cc,v 1.16.4.8 2005/09/29 22:56:59 dwsquid Exp $ * * DEBUG: section 73 HTTP Request * AUTHOR: Duane Wessels @@ -375,3 +375,40 @@ packableURI(full_uri), http_ver.major, http_ver.minor); } + +/* + * Indicate whether or not we would usually expect an entity-body + * along with this request + */ +bool +HttpRequest::expectingBody(method_t unused, ssize_t& theSize) +{ + bool expectBody = false; + + /* + * GET and HEAD don't usually have bodies, but we should be prepared + * to accept one if the request_entities directive is set + */ + + if (method == METHOD_GET || method == METHOD_HEAD) + expectBody = Config.onoff.request_entities ? true : false; + else if (method == METHOD_PUT || method == METHOD_POST) + expectBody = true; + else if (httpHeaderHasListMember(&header, HDR_TRANSFER_ENCODING, "chunked", ',')) + expectBody = true; + else if (content_length >= 0) + expectBody = true; + else + expectBody = false; + + if (expectBody) { + if (httpHeaderHasListMember(&header, HDR_TRANSFER_ENCODING, "chunked", ',')) + theSize = -1; + else if (content_length >= 0) + theSize = content_length; + else + theSize = -1; + } + + return expectBody; +} Index: squid3/src/HttpRequest.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/HttpRequest.h,v retrieving revision 1.13.4.5 retrieving revision 1.13.4.6 diff -u -r1.13.4.5 -r1.13.4.6 --- squid3/src/HttpRequest.h 19 Sep 2005 17:32:34 -0000 1.13.4.5 +++ squid3/src/HttpRequest.h 29 Sep 2005 22:56:59 -0000 1.13.4.6 @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.h,v 1.13.4.5 2005/09/19 17:32:34 dwsquid Exp $ + * $Id: HttpRequest.h,v 1.13.4.6 2005/09/29 22:56:59 dwsquid Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -97,6 +97,7 @@ public: bool parseFirstLine(const char *start, const char *end); int parseHeader(const char *parse_start); + virtual bool expectingBody(method_t unused, ssize_t&); private: const char *packableURI(bool full_uri) const;