/*
- * $Id: client_side.cc,v 1.226 1998/03/15 04:25:27 rousskov Exp $
+ * $Id: client_side.cc,v 1.227 1998/03/16 17:03:25 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
static int clientCachable(clientHttpRequest * http);
static int clientHierarchical(clientHttpRequest * http);
static int isTcpHit(log_type code);
-static int clientCheckContentLength(request_t *r);
+static int clientCheckContentLength(request_t * r);
static int
checkAccelOnly(clientHttpRequest * http)
}
static int
-clientCheckContentLength(request_t *r)
+clientCheckContentLength(request_t * r)
{
char *t;
int len;
/*
- * We only require a request content-length for POST and PUT
+ * We only require a content-length for "upload" methods
*/
- switch(r->method) {
- case METHOD_POST:
- case METHOD_PUT:
- break;
- default:
+ if (0 == pumpMethod(r->method))
return 1;
- break;
- }
t = mime_get_header(r->headers, "Content-Length");
- if (t == NULL)
+ if (NULL == t)
return 0;
len = atoi(t);
if (len < 0)
size_t len = 0;
size_t hdr_len = 0;
size_t l;
+ if (0 != strncmp(hdr_in, "HTTP/", 5))
+ return 0;
end = mime_headers_end(hdr_in);
if (end == NULL) {
debug(33, 3) ("clientBuildReplyHeader: DIDN'T FIND END-OF-HEADERS\n");
return;
}
/* yes, continue */
- } else if (r->method == METHOD_PUT || r->method == METHOD_POST) {
+ } else if (pumpMethod(r->method)) {
http->log_type = LOG_TCP_MISS;
/* XXX oof, POST can be cached! */
pumpInit(fd, r, http->uri);
} else {
- http->log_type = clientProcessRequest2(http);
+ http->log_type = clientProcessRequest2(http);
}
http->log_type = clientProcessRequest2(http);
debug(33, 4) ("clientProcessRequest: %s for '%s'\n",
/*
- * $Id: http.cc,v 1.252 1998/03/13 06:37:40 wessels Exp $
+ * $Id: http.cc,v 1.253 1998/03/16 17:03:26 wessels Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
static HttpStateData *httpBuildState(int, StoreEntry *, request_t *, peer *);
static int httpSocketOpen(StoreEntry *, request_t *);
static void httpRestart(HttpStateData *);
+static int httpTryRestart(HttpStateData *);
static int httpCachableReply(HttpStateData *);
static void
debug(50, 2) ("httpReadReply: FD %d: read failure: %s.\n",
fd, xstrerror());
} else if (len == 0 && entry->mem_obj->inmem_hi == 0) {
- if (fd_table[fd].uses > 1) {
+ if (httpTryRestart(httpState)) {
httpRestart(httpState);
} else {
httpState->eof = 1;
buflen += req->headers_sz + 1;
buflen += 512; /* lots of extra */
- if ((req->method == METHOD_POST || req->method == METHOD_PUT))
+ if (pumpMethod(req->method))
sendHeaderDone = httpSendRequestEntry;
else
sendHeaderDone = httpSendComplete;
cfd = entry->mem_obj->fd;
if (p != NULL)
EBIT_SET(httpState->flags, HTTP_PROXYING);
- if (req->method == METHOD_GET) {
- if (p == NULL)
- EBIT_SET(httpState->flags, HTTP_KEEPALIVE);
- else if (p->stats.n_keepalives_sent < 10)
- EBIT_SET(httpState->flags, HTTP_KEEPALIVE);
- else if ((double) p->stats.n_keepalives_recv / (double) p->stats.n_keepalives_sent > 0.50)
- EBIT_SET(httpState->flags, HTTP_KEEPALIVE);
- }
+ /*
+ * Is Keepalive okay for all request methods?
+ */
+ if (p == NULL)
+ EBIT_SET(httpState->flags, HTTP_KEEPALIVE);
+ else if (p->stats.n_keepalives_sent < 10)
+ EBIT_SET(httpState->flags, HTTP_KEEPALIVE);
+ else if ((double) p->stats.n_keepalives_recv / (double) p->stats.n_keepalives_sent > 0.50)
+ EBIT_SET(httpState->flags, HTTP_KEEPALIVE);
len = httpBuildRequestHeader(req,
httpState->orig_request,
entry,
sendHeaderDone,
httpState,
buftype == BUF_TYPE_8K ? memFree8K : xfree);
-#ifdef BREAKS_PCONN_RESTART
- requestUnlink(httpState->orig_request);
- httpState->orig_request = NULL;
-#endif
}
static int
httpState);
}
+static int
+httpTryRestart(HttpStateData * httpState)
+{
+ /*
+ * We only retry the request if it looks like it was
+ * on a persistent/pipelined connection
+ */
+ if (fd_table[httpState->fd].uses < 2)
+ return 0;
+ if (pumpMethod(httpState->orig_request->method))
+ if (0 == pumpRestart(httpState->orig_request))
+ return 0;
+ return 1;
+}
+
static void
httpRestart(HttpStateData * httpState)
{
/* restart a botched request from a persistent connection */
debug(11, 2) ("Retrying HTTP request for %s\n", storeUrl(httpState->entry));
if (httpState->orig_request->method != METHOD_GET) {
- debug(11, 1)("Potential Coredump: httpRestart %s %s\n",
- RequestMethodStr[httpState->orig_request->method],
- storeUrl(httpState->entry));
+ debug(11, 1) ("Potential Coredump: httpRestart %s %s\n",
+ RequestMethodStr[httpState->orig_request->method],
+ storeUrl(httpState->entry));
}
if (httpState->fd >= 0) {
comm_remove_close_handler(httpState->fd, httpStateFree, httpState);