diff --git a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java index 53b5a7e1d7..e5947c77bd 100755 --- a/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java +++ b/client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java @@ -173,20 +173,19 @@ private NettyResponseFuture newNettyRequestAndResponseFuture(final Reques ProxyServer proxy, boolean forceConnect) { Realm realm = null; - if (originalFuture != null) { + if (request.getRealm() != null) { + realm = request.getRealm(); + } else if (originalFuture != null && originalFuture.getRealm() != null) { realm = originalFuture.getRealm(); } else { - realm = request.getRealm(); - if (realm == null) { - realm = config.getRealm(); - } + realm = config.getRealm(); } Realm proxyRealm = null; - if (originalFuture != null) { - proxyRealm = originalFuture.getProxyRealm(); - } else if (proxy != null) { + if (proxy != null) { proxyRealm = proxy.getRealm(); + } else if (originalFuture != null) { + proxyRealm = originalFuture.getProxyRealm(); } NettyRequest nettyRequest = requestFactory.newNettyRequest(request, forceConnect, proxy, realm, proxyRealm);