This is an automated email from the ASF dual-hosted git repository. snagel pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nutch.git
commit 8b9714faf312973c91249077edc46c77abdc4c9c Author: Sebastian Nagel <[email protected]> AuthorDate: Fri Aug 17 11:45:37 2018 +0200 NUTCH-2632 protocol-okhttp doesn't accept proxy authentication - apply code formatting rules - add pointer to NUTCH-2636 and square/okhttp#3995 regarding limitations to use http.proxy.exclusion.list together with http.proxy.username --- .../org/apache/nutch/protocol/okhttp/OkHttp.java | 39 ++++++++++++++-------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java index 656bd19..f2558b9 100644 --- a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java +++ b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttp.java @@ -96,7 +96,8 @@ public class OkHttp extends HttpBase { } if (useProxy) { - Proxy proxy = new Proxy(proxyType, new InetSocketAddress(proxyHost, proxyPort)); + Proxy proxy = new Proxy(proxyType, + new InetSocketAddress(proxyHost, proxyPort)); String proxyUsername = conf.get("http.proxy.username"); if (proxyUsername == null) { ProxySelector selector = new ProxySelector() { @@ -112,6 +113,7 @@ public class OkHttp extends HttpBase { add(proxy); } }; + @Override public List<Proxy> select(URI uri) { if (useProxy(uri)) { @@ -119,29 +121,38 @@ public class OkHttp extends HttpBase { } return noProxyList; } + @Override - public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { + public void connectFailed(URI uri, SocketAddress sa, + IOException ioe) { LOG.error("Connection to proxy failed for {}: {}", uri, ioe); } }; builder.proxySelector(selector); } else { - // NOTE: the proxy exceptions list does NOT work with proxy username/password - // because an okhttp3 bug when using the ProxySelector class with proxy auth. - // If a proxy username is present, the configured proxy will be used for ALL - // requests. + /* + * NOTE: the proxy exceptions list does NOT work with proxy + * username/password because an okhttp3 bug + * (https://github.com/square/okhttp/issues/3995) when using the + * ProxySelector class with proxy auth. If a proxy username is present, + * the configured proxy will be used for ALL requests. + */ if (proxyException.size() > 0) { - LOG.warn("protocol-okhttp does not respect 'http.proxy.exception.list' setting when " + - "'http.proxy.username' is set. This is a limitation of the current okhttp3 implementation."); + LOG.warn( + "protocol-okhttp does not respect 'http.proxy.exception.list' setting when " + + "'http.proxy.username' is set. This is a limitation of the current okhttp3 " + + "implementation, see NUTCH-2636"); } builder.proxy(proxy); - String proxyPassword = conf.get("http.proxy.password"); + String proxyPassword = conf.get("http.proxy.password"); Authenticator proxyAuthenticator = new Authenticator() { - @Override public Request authenticate(okhttp3.Route route, okhttp3.Response response) throws IOException { - String credential = okhttp3.Credentials.basic(proxyUsername, proxyPassword); + @Override + public Request authenticate(okhttp3.Route route, + okhttp3.Response response) throws IOException { + String credential = okhttp3.Credentials.basic(proxyUsername, + proxyPassword); return response.request().newBuilder() - .header("Proxy-Authorization", credential) - .build(); + .header("Proxy-Authorization", credential).build(); } }; builder.proxyAuthenticator(proxyAuthenticator); @@ -149,7 +160,7 @@ public class OkHttp extends HttpBase { } if (storeIPAddress || storeHttpHeaders || storeHttpRequest) { - builder.addNetworkInterceptor(new HTTPHeadersInterceptor()); + builder.addNetworkInterceptor(new HTTPHeadersInterceptor()); } client = builder.build();
