[ https://issues.apache.org/jira/browse/HTTPCLIENT-2292?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17789846#comment-17789846 ]
Misagh Moayyed edited comment on HTTPCLIENT-2292 at 11/26/23 8:29 PM: ---------------------------------------------------------------------- This seems to have caused a regression in 5.2.2. {code:java} java.lang.IllegalArgumentException: Invalid Proxy at java.base/java.net.Socket.<init>(Socket.java:216) at org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory.createSocket(SSLConnectionSocketFactory.java:208) at org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158) at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:447) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:162) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:172) {code} When the proxy is undefined or set to null, DefaultHttpClientConnectionOperator does the following: {code:java} Timeout soTimeout = socketConfig.getSoTimeout(); SocketAddress socksProxyAddress = socketConfig.getSocksProxyAddress(); Proxy proxy = socksProxyAddress != null ? new Proxy(Type.SOCKS, socksProxyAddress) : null; {code} The proxy object above is then null, which means the following call: {code:java} Socket sock = sf.createSocket(proxy, context); {code} ...will eventually pass down to SSLConnectionSocketFactory which does this: {code:java} public Socket createSocket(Proxy proxy, HttpContext context) throws IOException { return new Socket(proxy); //this proxy cannot be null } {code} I think the code needs to do something like this: {code:java} if (proxy != null) { Socket sock = sf.createSocket(proxy, context); } else { Socket sock = sf.createSocket(context); }{code} I should mention that in the above case, - No SOCKS proxy is ever configured via the {{PoolingHttpClientConnectionManagerBuilder. setDefaultSocketConfig()}} method - No {{SocketConfig.setSocksProxyAddress(socksaddr)}} exists and is always null. was (Author: mmoayyed): This seems to have caused a regression in 5.2.2. {code:java} ava.lang.IllegalArgumentException: Invalid Proxy at java.base/java.net.Socket.<init>(Socket.java:216) at org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory.createSocket(SSLConnectionSocketFactory.java:208) at org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158) at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:447) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:162) at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:172) {code} When the proxy is undefined or set to null, DefaultHttpClientConnectionOperator does the following: {code:java} Timeout soTimeout = socketConfig.getSoTimeout(); SocketAddress socksProxyAddress = socketConfig.getSocksProxyAddress(); Proxy proxy = socksProxyAddress != null ? new Proxy(Type.SOCKS, socksProxyAddress) : null; {code} The proxy object above is then null, which means the following call: {code:java} Socket sock = sf.createSocket(proxy, context); {code} ...will eventually pass down to SSLConnectionSocketFactory which does this: {code:java} public Socket createSocket(Proxy proxy, HttpContext context) throws IOException { return new Socket(proxy); //this proxy cannot be null } {code} I think the code needs to do something like this: {code:java} if (proxy != null) { Socket sock = sf.createSocket(proxy, context); } else { Socket sock = sf.createSocket(context); }{code} I should mention that in the above case, - No SOCKS proxy is ever configured via the {{PoolingHttpClientConnectionManagerBuilder. setDefaultSocketConfig()}} method - No {{SocketConfig.setSocksProxyAddress(socksaddr)}} exists and is always null. > SOCKS proxy configuration is not working > ---------------------------------------- > > Key: HTTPCLIENT-2292 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2292 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient (classic) > Affects Versions: 5.2.1 > Reporter: Václav Kužel > Priority: Minor > Fix For: 5.2.2, 5.3-alpha2 > > > h3. Current behaviour > A SOCKS proxy can be configured via the > {{PoolingHttpClientConnectionManagerBuilder. setDefaultSocketConfig()}} > method which accepts {{SocketConfig.setSocksProxyAddress(socksaddr)}} > configuration. > **The {{socksProxyAddress}} configuration is ignored in class HttpClient** > h3. Expected behaviour > * Proxy aware socket instances are instantiated by the {{Socket(Proxy > proxy)}} constructor. > * Sockets are created via the {{ConnectionSocketFactory.createSocket()}} > method. > * The {{DefaultHttpClientConnectionOperator.connect()}} method, which holds > aforementioned configuration, calls the socket factory. > So, we need to pass the proxy address from the operator into the socket > factory method. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org For additional commands, e-mail: dev-h...@hc.apache.org