Skip to content

Commit 45dc585

Browse files
author
oleksiys
committed
[1.9.x] + fix issue AsyncHttpClient#959
"Grizzly: 401 response lost when no WWW-Authenticate header is present"
1 parent 6b54f74 commit 45dc585

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/main/java/com/ning/http/client/providers/grizzly/AhcEventFilter.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,10 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
490490
final FilterChainContext ctx) {
491491
final List<String> authHeaders = listOf(responsePacket.getHeaders()
492492
.values(Header.WWWAuthenticate));
493-
494-
if (authHeaders.isEmpty()) {
495-
throw new IllegalStateException("401 response received, but no WWW-Authenticate header was present");
496-
}
497-
498-
final GrizzlyAsyncHttpProvider provider =
499-
httpTransactionContext.provider;
500-
493+
501494
Realm realm = getRealm(httpTransactionContext);
502495

503-
if (realm == null) {
496+
if (authHeaders.isEmpty() || realm == null) {
504497
httpTransactionContext.invocationStatus = InvocationStatus.STOP;
505498
final AsyncHandler ah = httpTransactionContext.getAsyncHandler();
506499

@@ -515,6 +508,8 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
515508
return true;
516509
}
517510

511+
final GrizzlyAsyncHttpProvider provider =
512+
httpTransactionContext.provider;
518513
final Request req = httpTransactionContext.getAhcRequest();
519514

520515
try {
@@ -605,17 +600,9 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
605600
listOf(responsePacket.getHeaders()
606601
.values(Header.ProxyAuthenticate));
607602

608-
if (proxyAuthHeaders.isEmpty()) {
609-
throw new IllegalStateException("407 response received, but no "
610-
+ "Proxy-Authenticate header was present");
611-
}
612-
613-
final GrizzlyAsyncHttpProvider provider =
614-
httpTransactionContext.provider;
615-
616603
final ProxyServer proxyServer = httpTransactionContext.getProxyServer();
617604

618-
if (proxyServer == null) {
605+
if (proxyAuthHeaders.isEmpty() || proxyServer == null) {
619606
httpTransactionContext.invocationStatus = InvocationStatus.STOP;
620607
final AsyncHandler ah = httpTransactionContext.getAsyncHandler();
621608

@@ -630,6 +617,9 @@ public boolean handleStatus(final HttpResponsePacket responsePacket,
630617
return true;
631618
}
632619

620+
final GrizzlyAsyncHttpProvider provider =
621+
httpTransactionContext.provider;
622+
633623
final Request req = httpTransactionContext.getAhcRequest();
634624

635625
try {

src/test/java/com/ning/http/client/async/grizzly/GrizzlyUnexpectingTimeoutTest.java renamed to src/test/java/com/ning/http/client/async/grizzly/GrizzlyExpectingTimeoutTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012-2013 Sonatype, Inc. All rights reserved.
2+
* Copyright (c) 2012-2015 Sonatype, Inc. All rights reserved.
33
*
44
* This program is licensed to you under the Apache License Version 2.0,
55
* and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -35,16 +35,16 @@
3535
import java.util.concurrent.atomic.AtomicInteger;
3636

3737
import static org.testng.Assert.assertEquals;
38-
import static org.testng.Assert.assertFalse;
3938
import static org.testng.Assert.assertNull;
39+
import static org.testng.Assert.assertTrue;
4040
import static org.testng.Assert.fail;
4141

42-
public class GrizzlyUnexpectingTimeoutTest extends AbstractBasicTest {
42+
public class GrizzlyExpectingTimeoutTest extends AbstractBasicTest {
4343

4444
private static final String MSG = "Unauthorized without WWW-Authenticate header";
4545

4646
protected String getExpectedTimeoutMessage() {
47-
return "401 response received, but no WWW-Authenticate header was present";
47+
return "Timeout exceeded";
4848
}
4949

5050
@Override
@@ -80,7 +80,7 @@ public void run() {
8080
}
8181

8282
@Test(groups = {"standalone", "default_provider"})
83-
public void unexpectedTimeoutTest() throws IOException {
83+
public void expectedTimeoutTest() throws IOException {
8484
final AtomicInteger counts = new AtomicInteger();
8585
final int timeout = 100;
8686

@@ -107,7 +107,7 @@ public void onThrowable(Throwable t) {
107107
} catch (InterruptedException e) {
108108
fail("Interrupted.", e);
109109
} catch (ExecutionException e) {
110-
assertFalse(e.getCause() instanceof TimeoutException);
110+
assertTrue(e.getCause() instanceof TimeoutException);
111111
assertEquals(e.getCause().getMessage(), getExpectedTimeoutMessage());
112112
}
113113
// wait for timeout again.

0 commit comments

Comments
 (0)