I create a connection to send a GET to a third party system. For various safety reasons, I use a Squid as a proxy in between.
First I create a request:
var reqBuilder = new RequestBuilder(GET);
reqBuilder.setUrl(url);
Then I create a Realm with the username and password:
var realm = new Realm.Builder(proxyUser, proxySecret)
.setScheme(Realm.AuthScheme.BASIC);
var proxy = new ProxyServer.Builder(proxyHost, proxyPort)
.setSecuredPort(proxyPort)
.setProxyType(ProxyType.HTTP)
.setRealm(realm));
reqBuilder.setProxyServer(proxy);
(Here the ProxyHost
and ProxyPort
are the Squid IP:port.)
This works since we can actually see third party server receiving the GET as expected.
Finally I build the request itself and send it asynchronously.
Request request = reqBuilder.build();
asyncHttpClient.executeRequest(request);
(all details not shown, I don’t think the asyncHttpClient
is the issue)
What seems to happen is that the first request opens a connection to Squid and keeps that connection open. On the first connection, it sends the necessary headers so the Basic Auth happens. On subsequent requests, it seems to not send the Basic Auth… but Squid wants that data on each and every single request.
Is there a way to ask the Java Proxy to always send the Basic Auth info?
Details, the pertinent imports:
import org.asynchttpclient.Realm;
import org.asynchttpclient.Request;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.proxy.ProxyServer;
import org.asynchttpclient.proxy.ProxyType;