From: hno <> Date: Thu, 20 Mar 2003 01:06:45 +0000 (+0000) Subject: Bug #569: Must only reuse persistent connections on indempotent requests X-Git-Tag: SQUID_3_0_PRE1~257 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb9289091498fc4338a2362a06e8bd5fc1964545;p=thirdparty%2Fsquid.git Bug #569: Must only reuse persistent connections on indempotent requests --- diff --git a/src/forward.cc b/src/forward.cc index 29eb34f562..2fa9669a3d 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -1,6 +1,6 @@ /* - * $Id: forward.cc,v 1.100 2003/03/02 23:13:49 hno Exp $ + * $Id: forward.cc,v 1.101 2003/03/19 18:06:45 hno Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -175,6 +175,41 @@ fwdCheckRetry(FwdState * fwdState) return 1; } +static int +fwdCheckRetriable(FwdState * fwdState) +{ + /* If there is a request body then Squid can only try once + * even if the method is indempotent + */ + + if (fwdState->request->body_connection) + return 0; + + /* RFC2616 9.1 Safe and Idempotent Methods */ + switch (fwdState->request->method) { + /* 9.1.1 Safe Methods */ + + case METHOD_GET: + + case METHOD_HEAD: + /* 9.1.2 Indepontent Methods */ + + case METHOD_PUT: + + case METHOD_DELETE: + + case METHOD_OPTIONS: + + case METHOD_TRACE: + break; + + default: + return 0; + } + + return 1; +} + static void fwdServerClosed(int fd, void *data) { @@ -513,7 +548,7 @@ fwdConnectStart(void *data) { FwdState *fwdState = (FwdState *)data; const char *url = storeUrl(fwdState->entry); - int fd; + int fd = -1; ErrorState *err; FwdServer *fs = fwdState->servers; const char *host; @@ -537,13 +572,15 @@ fwdConnectStart(void *data) ctimeout = Config.Timeout.connect; } - if ((fd = pconnPop(host, port)) >= 0) { - debug(17, 3) ("fwdConnectStart: reusing pconn FD %d\n", fd); - fwdState->server_fd = fd; - fwdState->n_tries++; - comm_add_close_handler(fd, fwdServerClosed, fwdState); - fwdDispatch(fwdState); - return; + if (fwdCheckRetriable(fwdState)) { + if ((fd = pconnPop(host, port)) >= 0) { + debug(17, 3) ("fwdConnectStart: reusing pconn FD %d\n", fd); + fwdState->server_fd = fd; + fwdState->n_tries++; + comm_add_close_handler(fd, fwdServerClosed, fwdState); + fwdDispatch(fwdState); + return; + } } #if URL_CHECKSUM_DEBUG