Jetty’s HTTPCLIENT setup agent

void customizeHttpClient(HttpClient httpClient) throws URISyntaxException {
URI proxyURI = new URI("http://proxyhost:proxyport");
AuthenticationStore auth = httpClient.getAuthenticationStore();< br /> // Proxy credentials.
auth.addAuthentication(new BasicAuthentication(
proxyURI,
"Websense Content Gateway", // authentication domain
"username", // authentication User
"passwd")); // Authentication password

ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
HttpProxy proxy = new HttpProxy(proxyURI.getHost(), proxyURI. getPort());
proxyConfig.getProxies().add(proxy);
}

The value of the authentication domain is 407 Proxy Authorization Required response header Proxy-Authenticate: Basic Realm=”Websense Content Gateway” quoted part.

After the above configuration, you can use jetty’s HttpClient to send http requests through the proxy.

When the jetty-proxy module is used as a transparent proxy, the ProtocolHandler is cleared at the end of the call to createHttpClient() by AbstractProxyServlet (except for version 9.2.10.v20150310), which leads to if the jetty-proxy goes upstream If the request needs to go through a proxy, then the above configuration method does not work, jetty-proxy cannot automatically configure proxy authentication, and prompts that the request requires proxy authentication.

So you also need to add a ProxyAuthenticationProtocolHandler after calling the createHttpClient () method.

httpClient.getProtocolHandlers().put(new ProxyAuthenticationProtocolHandler(httpClient));

Code applicable jetty.version=9.4.6.v20170531

Leave a Comment

Your email address will not be published.