From: wessels <> Date: Tue, 27 Apr 1999 03:06:12 +0000 (+0000) Subject: added httpReplyBodySize() -- returns the size of a reply message body. X-Git-Tag: SQUID_3_0_PRE1~2248 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=35282fbf23e78baf8ebe01fb45537c5a66793148;p=thirdparty%2Fsquid.git added httpReplyBodySize() -- returns the size of a reply message body. Use it in http.c and client_side.c --- diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 21ff9430b9..4d286cc0e1 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -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; +} diff --git a/src/client_side.cc b/src/client_side.cc index 09d9220be7..a7362de59e 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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, diff --git a/src/http.cc b/src/http.cc index 743cb4965a..c0cf648592 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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 diff --git a/src/protos.h b/src/protos.h index db43b96500..d15bf4daf6 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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);