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

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4565 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.