From: Henrik Nordstrom Date: Mon, 24 Aug 2009 13:06:26 +0000 (+0200) Subject: Split out client_side_request connection pinning to a separate function X-Git-Tag: SQUID_3_2_0_1~764 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46a1f5628cb55fd4e2bb22c9267f4a0b7539d484;p=thirdparty%2Fsquid.git Split out client_side_request connection pinning to a separate function include requests from ESI may be without a client connection. This change splits out the client_side_request connection pinning logics to a separate function to ease code flow when there is no client connection. No code change except making that part conditional on http_conn being present. --- diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 0c92052ff4..02a6e58608 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -736,6 +736,67 @@ clientHierarchical(ClientHttpRequest * http) } +static void +clientCheckPinning(ClientHttpRequest * http) +{ + HttpRequest *request = http->request; + HttpHeader *req_hdr = &request->header; + ConnStateData *http_conn = http->getConn(); + + /* Internal requests such as those from ESI includes may be without + * a client connection + */ + if (!http_conn) + return; + + request->flags.connection_auth_disabled = http_conn->port->connection_auth_disabled; + if (!request->flags.connection_auth_disabled) { + if (http_conn->pinning.fd != -1) { + if (http_conn->pinning.auth) { + request->flags.connection_auth = 1; + request->flags.auth = 1; + } else { + request->flags.connection_proxy_auth = 1; + } + request->setPinnedConnection(http_conn); + } + } + + /* check if connection auth is used, and flag as candidate for pinning + * in such case. + * Note: we may need to set flags.connection_auth even if the connection + * is already pinned if it was pinned earlier due to proxy auth + */ + if (!request->flags.connection_auth) { + if (req_hdr->has(HDR_AUTHORIZATION) || req_hdr->has(HDR_PROXY_AUTHORIZATION)) { + HttpHeaderPos pos = HttpHeaderInitPos; + HttpHeaderEntry *e; + int may_pin = 0; + while ((e = req_hdr->getEntry(&pos))) { + if (e->id == HDR_AUTHORIZATION || e->id == HDR_PROXY_AUTHORIZATION) { + const char *value = e->value.rawBuf(); + if (strncasecmp(value, "NTLM ", 5) == 0 + || + strncasecmp(value, "Negotiate ", 10) == 0 + || + strncasecmp(value, "Kerberos ", 9) == 0) { + if (e->id == HDR_AUTHORIZATION) { + request->flags.connection_auth = 1; + may_pin = 1; + } else { + request->flags.connection_proxy_auth = 1; + may_pin = 1; + } + } + } + } + if (may_pin && !request->pinnedConnection()) { + request->setPinnedConnection(http->getConn()); + } + } + } +} + static void clientInterpretRequestHeaders(ClientHttpRequest * http) { @@ -845,55 +906,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http) if (req_hdr->has(HDR_AUTHORIZATION)) request->flags.auth = 1; - ConnStateData *http_conn = http->getConn(); - assert(http_conn); - request->flags.connection_auth_disabled = http_conn->port->connection_auth_disabled; - if (!request->flags.connection_auth_disabled) { - if (http_conn->pinning.fd != -1) { - if (http_conn->pinning.auth) { - request->flags.connection_auth = 1; - request->flags.auth = 1; - } else { - request->flags.connection_proxy_auth = 1; - } - request->setPinnedConnection(http_conn); - } - } - - /* check if connection auth is used, and flag as candidate for pinning - * in such case. - * Note: we may need to set flags.connection_auth even if the connection - * is already pinned if it was pinned earlier due to proxy auth - */ - if (!request->flags.connection_auth) { - if (req_hdr->has(HDR_AUTHORIZATION) || req_hdr->has(HDR_PROXY_AUTHORIZATION)) { - HttpHeaderPos pos = HttpHeaderInitPos; - HttpHeaderEntry *e; - int may_pin = 0; - while ((e = req_hdr->getEntry(&pos))) { - if (e->id == HDR_AUTHORIZATION || e->id == HDR_PROXY_AUTHORIZATION) { - const char *value = e->value.rawBuf(); - if (strncasecmp(value, "NTLM ", 5) == 0 - || - strncasecmp(value, "Negotiate ", 10) == 0 - || - strncasecmp(value, "Kerberos ", 9) == 0) { - if (e->id == HDR_AUTHORIZATION) { - request->flags.connection_auth = 1; - may_pin = 1; - } else { - request->flags.connection_proxy_auth = 1; - may_pin = 1; - } - } - } - } - if (may_pin && !request->pinnedConnection()) { - request->setPinnedConnection(http->getConn()); - } - } - } - + clientCheckPinning(http); if (request->login[0] != '\0') request->flags.auth = 1;