diff --git a/lib/url.c b/lib/url.c
index 085b3a2f9..c0aebef16 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -3133,8 +3133,10 @@ ConnectionExists(struct SessionHandle *data,
*force_reuse = TRUE;
break;
}
- else
- continue;
+ else if(credentialsMatch)
+ /* this is a backup choice */
+ chosen = check;
+ continue;
}
if(canPipeline) {
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index d526a4b69..53e8327fa 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -120,7 +120,7 @@ test1396 \
\
test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 \
test1408 test1409 test1410 test1412 test1413 test1414 test1415 \
-test1416 test1417 \
+test1416 test1417 test1418 test1419 \
\
test1500 test1501 test1502 test1503 test1504 test1505 test1506 test1507 \
test1508 test1509 test1510 test1511 test1512 test1513 test1514 test1515 \
diff --git a/tests/data/test1418 b/tests/data/test1418
new file mode 100644
index 000000000..fb4e91a23
--- /dev/null
+++ b/tests/data/test1418
@@ -0,0 +1,107 @@
+
+
+
+HTTP
+HTTP GET
+HTTP NTLM auth
+connection re-use
+
+
+# Server-side
+
+
+connection-monitor
+
+
+
+HTTP/1.1 401 Authentication please!
+Content-Length: 20
+WWW-Authenticate: Digest realm="loonie", nonce="314156592"
+WWW-Authenticate: Basic
+
+Please auth with me
+
+
+# This is supposed to be returned when the server gets the second
+# Authorization: NTLM line passed-in from the client
+
+HTTP/1.1 200 Things are fine in server land
+Server: Microsoft-IIS/5.0
+Content-Length: 4
+
+moo
+
+
+
+HTTP/1.1 200 OK
+Server: Another one/1.0
+Content-Length: 4
+
+boo
+
+
+# This is the first reply after the redirection
+
+HTTP/1.1 200 OK
+Server: Microsoft-IIS/5.0
+Content-Type: text/html; charset=iso-8859-1
+Content-Length: 34
+
+This is not the real page either!
+
+
+
+HTTP/1.1 401 Authentication please!
+Content-Length: 20
+WWW-Authenticate: Digest realm="loonie", nonce="314156592"
+WWW-Authenticate: Basic
+
+HTTP/1.1 200 Things are fine in server land
+Server: Microsoft-IIS/5.0
+Content-Length: 4
+
+moo
+
+
+
+
+# Client-side
+
+
+http
+
+
+crypto
+
+
+HTTP with --anyauth and connection re-use
+
+
+http://%HOSTIP:%HTTPPORT/1418 -u testuser:testpass --anyauth http://%HOSTIP:%HTTPPORT/14180003
+
+
+
+# Verify data after the test has been "shot"
+
+
+^User-Agent:.*
+
+
+GET /1418 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /1418 HTTP/1.1
+Authorization: Digest username="testuser", realm="loonie", nonce="314156592", uri="/1418", response="986238b7e0077754944c966f56d9bc77"
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /14180003 HTTP/1.1
+Authorization: Digest username="testuser", realm="loonie", nonce="314156592", uri="/14180003", response="1c6390a67bac3283a9b023402f3b3540"
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+[DISCONNECT]
+
+
+
diff --git a/tests/data/test1419 b/tests/data/test1419
new file mode 100644
index 000000000..f29ce4444
--- /dev/null
+++ b/tests/data/test1419
@@ -0,0 +1,69 @@
+
+
+
+HTTP
+HTTP GET
+HTTP NTLM auth
+connection re-use
+
+
+# Server-side
+
+
+connection-monitor
+
+
+
+HTTP/1.1 200 fine!
+Content-Length: 20
+
+Feel free to get it
+
+
+
+HTTP/1.1 200 OK
+Server: Another one/1.0
+Content-Length: 4
+
+boo
+
+
+
+HTTP/1.1 200 fine!
+Content-Length: 20
+
+Feel free to get it
+
+
+
+# Client-side
+
+
+http
+
+
+HTTP with --anyauth (but no auth!) and connection re-use
+
+
+http://%HOSTIP:%HTTPPORT/1419 --anyauth http://%HOSTIP:%HTTPPORT/14190003
+
+
+
+# Verify data after the test has been "shot"
+
+
+^User-Agent:.*
+
+
+GET /1419 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+GET /14190003 HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+
+[DISCONNECT]
+
+
+