]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Split out client_side_request connection pinning to a separate function
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Mon, 24 Aug 2009 13:06:26 +0000 (15:06 +0200)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Mon, 24 Aug 2009 13:06:26 +0000 (15:06 +0200)
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.

src/client_side_request.cc

index 0c92052ff411578a3a3b34da609f4fe7154fdb2e..02a6e5860821ea16fdfc2e17450f36fd290e0cbc 100644 (file)
@@ -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;