]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
added httpReplyBodySize() -- returns the size of a reply message body.
authorwessels <>
Tue, 27 Apr 1999 03:06:12 +0000 (03:06 +0000)
committerwessels <>
Tue, 27 Apr 1999 03:06:12 +0000 (03:06 +0000)
Use it in http.c and client_side.c

src/HttpReply.cc
src/client_side.cc
src/http.cc
src/protos.h

index 21ff9430b9cc879f186e22cbda8632a87d6b1cdc..4d286cc0e1e57a37461af9c84f9be8f6d96a1670 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpReply.cc,v 1.36 1999/04/23 02:57:16 wessels Exp $
+ * $Id: HttpReply.cc,v 1.37 1999/04/26 21:06:12 wessels Exp $
  *
  * DEBUG: section 58    HTTP Reply (Response)
  * AUTHOR: Alex Rousskov
@@ -401,3 +401,22 @@ httpReplyIsolateStart(const char **parse_start, const char **blk_start, const ch
     *parse_start = *blk_end;
     return 1;
 }
+
+/*
+ * Returns the body size of a HTTP response
+ */
+int
+httpReplyBodySize(method_t method, HttpReply * reply)
+{
+    if (METHOD_HEAD == method)
+       return 0;
+    else if (reply->sline.status == HTTP_OK)
+       (void) 0;               /* common case, continue */
+    else if (reply->sline.status == HTTP_NO_CONTENT)
+       return 0;
+    else if (reply->sline.status == HTTP_NOT_MODIFIED)
+       return 0;
+    else if (reply->sline.status < HTTP_OK)
+       return 0;
+    return reply->content_length;
+}
index 09d9220be730cca21e04b722d04a103319f06be2..a7362de59e887398bde78bed927baf2b1f691fb9 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.445 1999/04/26 21:04:42 wessels Exp $
+ * $Id: client_side.cc,v 1.446 1999/04/26 21:06:13 wessels Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -1093,9 +1093,11 @@ clientBuildRangeHeader(clientHttpRequest * http, HttpReply * rep)
     }
 }
 
-/* filters out unwanted entries from original reply header
+/*
+ * filters out unwanted entries from original reply header
  * adds extra entries if we have more info than origin server
- * adds Squid specific entries */
+ * adds Squid specific entries
+ */
 static void
 clientBuildReplyHeader(clientHttpRequest * http, HttpReply * rep)
 {
@@ -1162,12 +1164,10 @@ clientBuildReplyHeader(clientHttpRequest * http, HttpReply * rep)
        http->lookup_type ? http->lookup_type : "NONE",
        getMyHostname(), Config.Port.http->i);
 #endif
-    /*
-     * Clear keepalive for NON-HEAD requests with invalid content length
-     */
-    if (request->method != METHOD_HEAD)
-       if (http->entry->mem_obj->reply->content_length < 0)
-           request->flags.proxy_keepalive = 0;
+    if (httpReplyBodySize(request->method, http->entry->mem_obj->reply) < 0) {
+       debug(0, 0) ("persistent connection lossage\n");
+       request->flags.proxy_keepalive = 0;
+    }
     /* Signal keep-alive if needed */
     httpHeaderPutStr(hdr,
        http->flags.accel ? HDR_CONNECTION : HDR_PROXY_CONNECTION,
index 743cb4965a01ecb5aaae962dfdd0c35df199021b..c0cf648592aee4f4138cb74629b34adf718bb37a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: http.cc,v 1.347 1999/04/15 06:15:58 wessels Exp $
+ * $Id: http.cc,v 1.348 1999/04/26 21:06:15 wessels Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -374,6 +374,7 @@ httpPconnTransferDone(HttpStateData * httpState)
     /* return 1 if we got the last of the data on a persistent connection */
     MemObject *mem = httpState->entry->mem_obj;
     HttpReply *reply = mem->reply;
+    int clen;
     debug(11, 3) ("httpPconnTransferDone: FD %d\n", httpState->fd);
     /*
      * If we didn't send a keep-alive request header, then this
@@ -397,40 +398,21 @@ httpPconnTransferDone(HttpStateData * httpState)
        return 0;
     debug(11, 5) ("httpPconnTransferDone: content_length=%d\n",
        reply->content_length);
-    /*
-     * Deal with gross HTTP stuff
-     *    - If we haven't seen the end of the reply headers, we can't
-     *      be persistent.
-     *    - For HEAD requests we're done.
-     *    - For "200 OK" check the content-length in the next block.
-     *    - For "204 No Content" (even with content-length) we're done.
-     *    - For "304 Not Modified" (even with content-length) we're done.
-     *    - 1XX replies never have a body; we're done.
-     *    - For all other replies, check content length in next block.
-     */
+    /* If we haven't seen the end of reply headers, we are not done */
     if (httpState->reply_hdr_state < 2)
        return 0;
-    else if (httpState->request->method == METHOD_HEAD)
-       return 1;
-    else if (reply->sline.status == HTTP_OK)
-       (void) 0;               /* common case, continue */
-    else if (reply->sline.status == HTTP_NO_CONTENT)
-       return 1;
-    else if (reply->sline.status == HTTP_NOT_MODIFIED)
-       return 1;
-    else if (reply->sline.status < HTTP_OK)
+    clen = httpReplyBodySize(httpState->request->method, reply);
+    /* If there is no message body, we can be persistent */
+    if (0 == clen)
        return 1;
-    /*
-     * If there is no content-length, then we can't be
-     * persistent.  If there is a content length, then we must
-     * wait until we've seen the end of the body.
-     */
-    if (reply->content_length < 0)
+    /* If the body size is unknown we must wait for EOF */
+    if (clen < 0)
        return 0;
-    else if (mem->inmem_hi < reply->content_length + reply->hdr_sz)
+    /* If the body size is known, we must wait until we've gotten all of it.  */
+    if (mem->inmem_hi < reply->content_length + reply->hdr_sz)
        return 0;
-    else
-       return 1;
+    /* We got it all */
+    return 1;
 }
 
 /* This will be called when data is ready to be read from fd.  Read until
index db43b96500f7e1dbf3b021766ff31d1cf9bfb7c8..d15bf4daf660ec5ca448b7df471c40e71e83aaf5 100644 (file)
@@ -1,7 +1,7 @@
 
 /*
- * $Id: protos.h,v 1.323 1999/04/26 21:04:46 wessels Exp $
- * $Id: protos.h,v 1.323 1999/04/26 21:04:46 wessels Exp $
+ * $Id: protos.h,v 1.324 1999/04/26 21:06:16 wessels Exp $
+ * $Id: protos.h,v 1.324 1999/04/26 21:06:16 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -469,6 +469,7 @@ extern const char *httpReplyContentType(const HttpReply * rep);
 extern time_t httpReplyExpires(const HttpReply * rep);
 extern int httpReplyHasCc(const HttpReply * rep, http_hdr_cc_type type);
 extern void httpRedirectReply(HttpReply *, http_status, const char *);
+extern int httpReplyBodySize(method_t, HttpReply *);
 
 /* Http Request */
 extern request_t *requestCreate(method_t, protocol_t, const char *urlpath);