webmetrics / browsermob-proxy

NOTICE: this project has been forked and is being maintained at https://github.com/lightbody/browsermob-proxy
https://github.com/lightbody/browsermob-proxy
Apache License 2.0
234 stars 773 forks source link

java.net.UnknownHostException when ProxyServer has upstream proxy #24

Closed JuanCerezuela closed 11 years ago

JuanCerezuela commented 12 years ago

WHEN ProxyServer is configured to use an upstream HTTP and SSL proxy: final ProxyServer proxyServer = new ProxyServer(browserMobProxyPort); Map<String,String> options = new HashMap<String, String>(); options.put("httpProxy", upstreamProxyHost + ":" + upstreamProxyPort); proxyServer.start(); proxyServer.setOptions(options);

THEN A java.net.UnknownHostException is thrown when I request a SSL connection from the browser:

10:30:28,758 DEBUG HttpConnection:990 - EXCEPTION EOFException() at org.browsermob.proxy.jetty.http.HttpRequest.readHeader(HttpRequest.java: 222) at org.browsermob.proxy.jetty.http.HttpConnection.readRequest(HttpConnection.java: 861) at org.browsermob.proxy.jetty.http.HttpConnection.handleNext(HttpConnection.java: 907) at org.browsermob.proxy.jetty.http.HttpConnection.handle(HttpConnection.java: 832) at org.browsermob.proxy.jetty.http.SocketListener.handleConnection(SocketListener.java: 245) at org.browsermob.proxy.jetty.util.ThreadedServer.handle(ThreadedServer.java: 357) at org.browsermob.proxy.jetty.util.ThreadPool $PoolThread.run(ThreadPool.java:534) 10:30:28,793 INFO JavaScriptErrorHuntingSmokeTest:? - Testing testOpenHomePage: https://www.pcisecuritystandards.org/ 10:30:28,793 INFO JavaScriptErrorHuntingSmokeTest:? - Testing testOpenHomePage: https://www.pcisecuritystandards.org/ 10:30:28,802 DEBUG HttpConnection:110 - new HttpConnection: Socket[addr=/127.0.0.1,port=64962,localport=4449] 10:30:28,802 DEBUG HttpConnection:973 - REQUEST from SocketListener0@0.0.0.0:4449: CONNECT www.pcisecuritystandards.org:443 HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0 Proxy-Connection: keep-alive Host: www.pcisecuritystandards.org

10:30:28,802 DEBUG HttpServer:876 - Contexts at www.pcisecuritystandards.org:443: [/=[HttpContext[/,/]]] 10:30:28,802 DEBUG HttpServer:890 - Try HttpContext[/,/],0 10:30:28,803 DEBUG HttpContext:1508 - Handler org.browsermob.proxy.BrowserMobProxyHandler in HttpContext[/,/] 10:30:28,803 DEBUG HttpContext:1513 - Handled by org.browsermob.proxy.BrowserMobProxyHandler in HttpContext[/,/] 10:30:28,803 DEBUG HttpInputStream:231 - resetStream() 10:30:28,804 DEBUG HttpConnection:1077 - RESPONSE: HTTP/1.1 500 java%2Enet%2EUnknownHostException%3A+www %2Epcisecuritystandards%2Eorg Date: Fri, 02 Dec 2011 09:30:28 GMT Server: Jetty/5.1.x (Windows 7/6.1 amd64 java/1.6.0_29 Connection: close Content-Type: text/html Content-Length: 1342

lightbody commented 12 years ago

It's still not entirely clear what your test case is. If you could attach an actual unit test, that would be really helpful.

JuanCerezuela commented 12 years ago

Hi Patrick

At work all the traffic is proxied through "myproxy:8080". When I run this test, the browser is not loading the OWASP webpage on the testSSL() test case, but I can see the page is loaded on testHttp()

Cheers! Juan

P:S. happy new year :)

import java.util.HashMap; import java.util.Map;

import com.google.sitebricks.client.Web; import org.browsermob.proxy.util.Log; import org.junit.Before; import org.junit.After; import org.junit.Test; import org.openqa.selenium.Proxy; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile;

/**

public class UnknownHostExceptionUnitTest { private static final Log LOG = new Log(); WebDriver driver; ProxyServer proxyServer; public static int browserMobProxyPort = 4448; String upstreamProxyHost = "myproxy"; String upstreamProxyPort = "8080";

@Before
public void setUp() throws Exception {
    proxyServer = new ProxyServer(browserMobProxyPort);
    Map<String,String> options = new HashMap<String, String>();
    options.put("httpProxy", upstreamProxyHost + ":" +

upstreamProxyPort); proxyServer.start(); proxyServer.setOptions(options); }

@After
public void tearDown() throws Exception {
    proxyServer.stop();
}

public WebDriver launchDriver(){
    FirefoxProfile profile = new FirefoxProfile();
    Proxy proxy = new Proxy();
    proxy.setHttpProxy("localhost:" + browserMobProxyPort);
    proxy.setSslProxy("localhost:" + browserMobProxyPort);
    profile.setProxyPreferences(proxy);
    return new FirefoxDriver(profile);
}

@Test
public void testHttp() throws Exception {
    LOG.info("Testing with plaintext HTTP traffic");
    driver = launchDriver();
    driver.get("http://www.apache.org");
    Thread.sleep(2000);
    driver.close();
}

@Test
public void testSSL() throws Exception {
    LOG.info("Testing with SSL traffic");
    driver = launchDriver();
    driver.get("https://www.owasp.org");
    Thread.sleep(10000);
    driver.close();
}

}

On 2 January 2012 09:50, Patrick Lightbody < reply@reply.github.com

wrote:

It's still not entirely clear what your test case is. If you could attach an actual unit test, that would be really helpful.


Reply to this email directly or view it on GitHub:

https://github.com/webmetrics/browsermob-proxy/issues/24#issuecomment-3328112

JuanCerezuela commented 12 years ago

Hi Patrick, did you manage to reproduce the issue?

lightbody commented 12 years ago

Juan, Unfortunately, no. The issue is I don't know what kind of proxy you're using. Can the problem be reproduced with any proxy running at "upstreamProxyHost:upstreamProxyPort"? What proxy are you running? It would be nice if your test case included instructions for getting the entire environment set up - including the upstream proxy.

Thanks!

Patrick

nirvdrum commented 11 years ago

I'm seeing SSL connection issues when using an upstream proxy. I'm using the Apache Traffic Server product. I can double-check this on Squid, too. But it sounds like it may just be a general issue with SSL connections being routed through an upstream proxy.

nirvdrum commented 11 years ago

I'm really not sure if what I was seeing was this issue. I filed mine as #79, which has been fixed in master.

lightbody commented 11 years ago

Closing this out since I can't reproduce.