You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Mikolaj Broniszewski (JIRA)" <ji...@apache.org> on 2019/01/24 12:51:00 UTC

[jira] [Created] (HTTPCLIENT-1966) System Proxy - HTTP and SOCKS

Mikolaj Broniszewski created HTTPCLIENT-1966:
------------------------------------------------

             Summary: System Proxy - HTTP and SOCKS
                 Key: HTTPCLIENT-1966
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1966
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient (Windows)
    Affects Versions: 4.5.6, 4.5.5
            Reporter: Mikolaj Broniszewski


Hello,

I have created a proxy server basing on squid solution. And I have hidden the server (Apache Tomcat 8) which I would like to access behind this proxy (it's not available from my local machine directly). Then, I have created an example project which only connects to this hidden server basing on Apache HttpClient libraries:
 * org.apache.httpcomponents:httpcore:4.4.11
 * org.apache.httpcomponents:httpclient:4.5.6

The code looks like:
{code:java}
public static void main(String ...args) throws Exception {
	System.setProperty("https.proxyHost", "<proxy_url>");
	System.setProperty("https.proxyPort", "<proxy_port>");
	System.setProperty("socksProxyHost", "<proxy_url>");
	System.setProperty("socksProxyPort", "<proxy_port>");

	URI uri = new URI("https://<hidden_server_url>");
	try (CloseableHttpClient build = HttpClientBuilder.create()
			.useSystemProperties()
			.build()) {
		final HttpUriRequest uriRequest = RequestBuilder.get()
				.setUri(uri)
				.build();
		try (CloseableHttpResponse response = build.execute(uriRequest)) {
			final StatusLine statusLine = response.getStatusLine();
			System.out.println(statusLine.toString());
		}
	}
}
{code}
Unfortunately, as squid does not support SOCKS protocol, opening socket and waiting for response hangs the program. I was thinking that maybe I'm basing on invalid server configuration however when using below code everything works fine for same system properties:
{code:java}
public static void main(String ...args) throws Exception {
	System.setProperty("https.proxyHost", "<proxy_url>");
	System.setProperty("https.proxyPort", "<proxy_port>");
	System.setProperty("socksProxyHost", "<proxy_url>");
	System.setProperty("socksProxyPort", "<proxy_port>");

	URI uri = new URI("https://<hidden_server_url>");
	try (InputStream stream = uri.toURL().openStream()){
		String s = IOUtils.toString(stream, "UTF-8");
		System.out.println(s != null);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
{code}
So java itself handles it correctly. What is more if I simply remove the socksProxyHost and socksProxyPort settings, then Apache HttpClient connects correctly to the hidden server. I don't think that having both HTTPS proxy configuration and SOCKS is incorrect as according to Oracle documentation:

[https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html]
{code:java}
"Now, what happens when both a SOCKS proxy and a HTTP proxy are defined? Well the rule is that settings for higher level protocols, like HTTP or FTP, take precedence over SOCKS settings. So, in that particular case, when establishing a HTTP connection, the SOCKS proxy settings will be ignored and the HTTP proxy will be contacted. Let's look at an example:"
{code}
As in Apache HttpClient I'm using system properties (useSystemProperties) I would expect that it is handled the same as Oracle does (the SOCK proxy should be ignored). I also checked it for simple HTTP proxy (http.proxyHost, http.proxyPort) and it acts the same (fails).

Could you please help me with this issue?

Best regards,
 Mikolaj Broniszewski



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org