aboutsummaryrefslogtreecommitdiff
path: root/lib/url.c
diff options
context:
space:
mode:
authorJoe Mason <jmason@rim.com>2012-08-20 17:00:40 -0400
committerDaniel Stenberg <daniel@haxx.se>2012-08-31 22:54:23 +0200
commit5ede86ae51b8f71be35152584815f80dbd5a327a (patch)
treea4fb7292af33ff6602ed8df522cd0b63bb2200b9 /lib/url.c
parent3b7d31c1eddc52431d8944aae6c7ab8aa7e29570 (diff)
NTLM: re-use existing connection better
If we need an NTLM connection and one already exists, always choose that one.
Diffstat (limited to 'lib/url.c')
-rw-r--r--lib/url.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/lib/url.c b/lib/url.c
index c2f488280..c05c50e62 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2928,10 +2928,14 @@ ConnectionExists(struct SessionHandle *data,
{
long i;
struct connectdata *check;
+ struct connectdata *chosen = 0;
bool canPipeline = IsPipeliningPossible(data, needle);
+ bool wantNTLM = (data->state.authhost.want==CURLAUTH_NTLM) ||
+ (data->state.authhost.want==CURLAUTH_NTLM_WB);
for(i=0; i< data->state.connc->num; i++) {
bool match = FALSE;
+ bool credentialsMatch = FALSE;
size_t pipeLen = 0;
/*
* Note that if we use a HTTP proxy, we check connections to that
@@ -3102,9 +3106,7 @@ ConnectionExists(struct SessionHandle *data,
}
}
if((needle->handler->protocol & CURLPROTO_FTP) ||
- ((needle->handler->protocol & CURLPROTO_HTTP) &&
- ((data->state.authhost.want==CURLAUTH_NTLM) ||
- (data->state.authhost.want==CURLAUTH_NTLM_WB)))) {
+ ((needle->handler->protocol & CURLPROTO_HTTP) && wantNTLM)) {
/* This is FTP or HTTP+NTLM, verify that we're using the same name
and password as well */
if(!strequal(needle->user, check->user) ||
@@ -3112,6 +3114,7 @@ ConnectionExists(struct SessionHandle *data,
/* one of them was different */
continue;
}
+ credentialsMatch = TRUE;
}
match = TRUE;
}
@@ -3129,14 +3132,29 @@ ConnectionExists(struct SessionHandle *data,
}
if(match) {
- check->inuse = TRUE; /* mark this as being in use so that no other
- handle in a multi stack may nick it */
+ chosen = check;
- *usethis = check;
- return TRUE; /* yes, we found one to use! */
+ /* If we are not looking for an NTLM connection, we can choose this one
+ immediately. */
+ if(!wantNTLM)
+ break;
+
+ /* Otherwise, check if this is already authenticating with the right
+ credentials. If not, keep looking so that we can reuse NTLM
+ connections if possible. (Especially we must reuse the same
+ connection if partway through a handshake!) */
+ if(credentialsMatch && chosen->ntlm.state != NTLMSTATE_NONE)
+ break;
}
}
+ if(chosen) {
+ chosen->inuse = TRUE; /* mark this as being in use so that no other
+ handle in a multi stack may nick it */
+ *usethis = chosen;
+ return TRUE; /* yes, we found one to use! */
+ }
+
return FALSE; /* no matching connecting exists */
}