Squid-2.2.STABLE4: Support generic request entities Support generic request entities as needed by WebDAV (RFC 2518). Now it is theoretically possible to use WebDAV with Squid, but only if the server does not do strict HTTP/1.1 version checks (Squid still downgrades requests to HTTP/1.0 as required by HTTP standars). You will also need the patch from below adding the new methods to the list of known HTTP methods. Index: squid/src/client_side.c diff -u squid/src/client_side.c:1.1.1.42.2.3 squid/src/client_side.c:1.1.1.42.2.4 --- squid/src/client_side.c:1.1.1.42.2.3 Tue Jul 13 00:49:10 1999 +++ squid/src/client_side.c Tue Jul 13 01:12:45 1999 @@ -839,12 +839,21 @@ static int clientCheckContentLength(request_t * r) { - /* We only require a content-length for "upload" methods */ - if (!pumpMethod(r->method)) + int has_cont_len = (httpHeaderGetInt(&r->header, HDR_CONTENT_LENGTH) >= 0); + switch (r->method) { + case METHOD_PUT: + case METHOD_POST: + /* PUT/POST requires a request entity */ + return has_cont_len; + case METHOD_GET: + case METHOD_HEAD: + /* We do not want to see a request entity on GET/HEAD requests */ + return !has_cont_len; + default: + /* For other types of requests we don't care */ return 1; - if (httpHeaderGetInt(&r->header, HDR_CONTENT_LENGTH) < 0) - return 0; - return 1; + } + /* NOT REACHED */ } static int @@ -1790,7 +1799,7 @@ } /* yes, continue */ http->log_type = LOG_TCP_MISS; - } else if (pumpMethod(r->method)) { + } else if (r->body) { http->log_type = LOG_TCP_MISS; /* XXX oof, POST can be cached! */ pumpInit(fd, r, http->uri); @@ -2136,6 +2145,7 @@ int k; request_t *request = NULL; int size; + int cont_len; method_t method; clientHttpRequest *http = NULL; clientHttpRequest **H = NULL; @@ -2305,22 +2315,18 @@ */ clientSetKeepaliveFlag(http); /* - * break here for NON-GET because most likely there is a - * reqeust body following and we don't want to parse it - * as though it was new request + * break here if the request has a content-length. */ - if (request->method != METHOD_GET) { - int cont_len = httpHeaderGetInt(&request->header, HDR_CONTENT_LENGTH); + cont_len = httpHeaderGetInt(&request->header, HDR_CONTENT_LENGTH); + if (cont_len >= 0) { int copy_len = XMIN(conn->in.offset, cont_len); - if (copy_len > 0) { - assert(conn->in.offset >= copy_len); - request->body_sz = copy_len; - request->body = xmalloc(request->body_sz); - xmemcpy(request->body, conn->in.buf, request->body_sz); - conn->in.offset -= copy_len; - if (conn->in.offset) - xmemmove(conn->in.buf, conn->in.buf + copy_len, conn->in.offset); - } + assert(conn->in.offset >= copy_len); + request->body_sz = copy_len; + request->body = xmalloc(request->body_sz); + xmemcpy(request->body, conn->in.buf, request->body_sz); + conn->in.offset -= copy_len; + if (conn->in.offset) + xmemmove(conn->in.buf, conn->in.buf + copy_len, conn->in.offset); /* * if we didn't get the full body now, then more will * be arriving on the client socket. Lets cancel Index: squid/src/forward.c diff -u squid/src/forward.c:1.1.1.14.2.4 squid/src/forward.c:1.1.1.14.2.5 --- squid/src/forward.c:1.1.1.14.2.4 Tue Jul 13 00:37:18 1999 +++ squid/src/forward.c Tue Jul 13 01:12:47 1999 @@ -112,7 +112,7 @@ return 0; if (fwdState->flags.dont_retry) return 0; - if (pumpMethod(fwdState->request->method)) + if (fwdState->request->body) if (0 == pumpRestart(fwdState->request)) return 0; return 1; @@ -375,7 +375,7 @@ } if (fwdState->n_tries > 9) return 0; - if (pumpMethod(fwdState->request->method)) + if (fwdState->request->body) if (0 == pumpRestart(fwdState->request)) return 0; assert(fs); Index: squid/src/http.c diff -u squid/src/http.c:1.1.1.35.2.2 squid/src/http.c:1.1.1.35.2.3 --- squid/src/http.c:1.1.1.35.2.2 Tue Jul 13 00:45:18 1999 +++ squid/src/http.c Tue Jul 13 01:12:47 1999 @@ -833,7 +833,7 @@ debug(11, 5) ("httpSendRequest: FD %d: httpState %p.\n", httpState->fd, httpState); - if (pumpMethod(req->method)) + if (httpState->orig_request->body) sendHeaderDone = httpSendRequestEntry; else sendHeaderDone = httpSendComplete; Index: squid/src/pump.c diff -u squid/src/pump.c:1.1.1.16 squid/src/pump.c:1.1.1.16.2.1 --- squid/src/pump.c:1.1.1.16 Tue Jul 13 00:09:33 1999 +++ squid/src/pump.c Tue Jul 13 01:12:47 1999 @@ -408,25 +408,6 @@ } /* - * This function returns true for the request methods handled - * by this module - */ -int -pumpMethod(method_t method) -{ - switch (method) { - case METHOD_POST: - case METHOD_PUT: - return 1; - break; - default: - return 0; - break; - } - /* NOTREACHED */ -} - -/* * This function returns True if we can submit this request again. * The request may have been pipelined, but the connection got * closed before we got a reply. If we still have the whole