]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added HttpReply::expectingBody() method to indicate whether or not
authorwessels <>
Tue, 22 Nov 2005 05:49:04 +0000 (05:49 +0000)
committerwessels <>
Tue, 22 Nov 2005 05:49:04 +0000 (05:49 +0000)
we would usually expect an entity-body in the HTTP response.

This was done for ICAP integration.

src/HttpReply.cc
src/HttpReply.h

index 6fbe9aca7ce164c90596d7808288c7b6066c6abf..40c3895edfeec8536f878ad82be5fd8cfbe79a6a 100644 (file)
@@ -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;
+}
index 35be53b92beaa0e614f4c06a66826347ef22419a..1970d510dc82456577644ef7298657736d74235b 100644 (file)
@@ -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);