Skip to content

Commit 2ed3b4c

Browse files
author
Stephane Landelle
committed
systematicProxyAuthorizationHeader should honor Real when targeting a proxy, close AsyncHttpClient#803
1 parent 27b9094 commit 2ed3b4c

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

providers/netty3/src/main/java/org/asynchttpclient/providers/netty3/request/NettyRequestFactory.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,32 @@ public String firstRequestOnlyProxyAuthorizationHeader(Request request, ProxySer
176176
return proxyAuthorization;
177177
}
178178

179-
private String systematicProxyAuthorizationHeader(Request request, ProxyServer proxyServer, HttpMethod method) {
179+
private String systematicProxyAuthorizationHeader(Request request, ProxyServer proxyServer, Realm realm, HttpMethod method) {
180180

181181
String proxyAuthorization = null;
182182

183183
if (method != HttpMethod.CONNECT && proxyServer != null && proxyServer.getPrincipal() != null && proxyServer.getScheme() == AuthScheme.BASIC) {
184184
proxyAuthorization = computeBasicAuthentication(proxyServer);
185+
186+
} else if (realm != null && realm.getUsePreemptiveAuth() && realm.isTargetProxy()) {
187+
188+
switch (realm.getScheme()) {
189+
case BASIC:
190+
proxyAuthorization = computeBasicAuthentication(realm);
191+
break;
192+
case DIGEST:
193+
if (isNonEmpty(realm.getNonce()))
194+
proxyAuthorization = computeDigestAuthentication(realm);
195+
break;
196+
case NTLM:
197+
case KERBEROS:
198+
case SPNEGO:
199+
// NTLM, KERBEROS and SPNEGO are only set on the first request, see firstRequestOnlyAuthorizationHeader
200+
case NONE:
201+
break;
202+
default:
203+
throw new IllegalStateException("Invalid Authentication " + realm);
204+
}
185205
}
186206

187207
return proxyAuthorization;
@@ -328,7 +348,7 @@ public NettyRequest newNettyRequest(Request request, Uri uri, boolean forceConne
328348
// don't override authorization but append
329349
addAuthorizationHeader(headers, systematicAuthorizationHeader(request, uri, realm));
330350

331-
setProxyAuthorizationHeader(headers, systematicProxyAuthorizationHeader(request, proxyServer, method));
351+
setProxyAuthorizationHeader(headers, systematicProxyAuthorizationHeader(request, proxyServer, realm, method));
332352

333353
// Add default accept headers
334354
if (!headers.contains(HttpHeaders.Names.ACCEPT))

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/request/NettyRequestFactory.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,31 @@ public String firstRequestOnlyProxyAuthorizationHeader(Request request, ProxySer
177177
return proxyAuthorization;
178178
}
179179

180-
private String systematicProxyAuthorizationHeader(Request request, ProxyServer proxyServer, HttpMethod method) {
180+
private String systematicProxyAuthorizationHeader(Request request, ProxyServer proxyServer, Realm realm, HttpMethod method) {
181181

182182
String proxyAuthorization = null;
183183

184184
if (method != HttpMethod.CONNECT && proxyServer != null && proxyServer.getPrincipal() != null && proxyServer.getScheme() == AuthScheme.BASIC) {
185185
proxyAuthorization = computeBasicAuthentication(proxyServer);
186+
} else if (realm != null && realm.getUsePreemptiveAuth() && realm.isTargetProxy()) {
187+
188+
switch (realm.getScheme()) {
189+
case BASIC:
190+
proxyAuthorization = computeBasicAuthentication(realm);
191+
break;
192+
case DIGEST:
193+
if (isNonEmpty(realm.getNonce()))
194+
proxyAuthorization = computeDigestAuthentication(realm);
195+
break;
196+
case NTLM:
197+
case KERBEROS:
198+
case SPNEGO:
199+
// NTLM, KERBEROS and SPNEGO are only set on the first request, see firstRequestOnlyAuthorizationHeader
200+
case NONE:
201+
break;
202+
default:
203+
throw new IllegalStateException("Invalid Authentication " + realm);
204+
}
186205
}
187206

188207
return proxyAuthorization;
@@ -329,7 +348,7 @@ public NettyRequest newNettyRequest(Request request, Uri uri, boolean forceConne
329348
// don't override authorization but append
330349
addAuthorizationHeader(headers, systematicAuthorizationHeader(request, uri, realm));
331350

332-
setProxyAuthorizationHeader(headers, systematicProxyAuthorizationHeader(request, proxyServer, method));
351+
setProxyAuthorizationHeader(headers, systematicProxyAuthorizationHeader(request, proxyServer, realm, method));
333352

334353
// Add default accept headers
335354
if (!headers.contains(HttpHeaders.Names.ACCEPT))

0 commit comments

Comments
 (0)