/*
- * $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
*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;
+}
/*
- * $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
}
}
-/* 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)
{
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,
/*
- * $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
/* 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
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
/*
- * $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/
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);