Merged branch 'master' into 'jetty-9.1'.

This commit is contained in:
Simone Bordet 2013-07-25 17:11:09 +02:00
commit 8c2be70330
2 changed files with 51 additions and 6 deletions

View File

@ -129,7 +129,8 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res
if (exchange == null) if (exchange == null)
return false; return false;
parser.setHeadResponse(HttpMethod.HEAD.is(exchange.getRequest().getMethod())); String method = exchange.getRequest().getMethod();
parser.setHeadResponse(HttpMethod.HEAD.is(method) || HttpMethod.CONNECT.is(method));
exchange.getResponse().version(version).status(status).reason(reason); exchange.getResponse().version(version).status(status).reason(reason);
responseBegin(exchange); responseBegin(exchange);
@ -177,7 +178,7 @@ public class HttpReceiverOverHTTP extends HttpReceiver implements HttpParser.Res
return false; return false;
responseSuccess(exchange); responseSuccess(exchange);
return false; return true;
} }
@Override @Override

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.proxy;
import java.io.IOException; import java.io.IOException;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.Socket;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -55,6 +56,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Assume;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -115,16 +117,22 @@ public class ProxyTunnellingTest
} }
protected void stopServer() throws Exception protected void stopServer() throws Exception
{
if (server != null)
{ {
server.stop(); server.stop();
server.join(); server.join();
} }
}
protected void stopProxy() throws Exception protected void stopProxy() throws Exception
{
if (proxy != null)
{ {
proxy.stop(); proxy.stop();
proxy.join(); proxy.join();
} }
}
@Test @Test
public void testOneExchangeViaSSL() throws Exception public void testOneExchangeViaSSL() throws Exception
@ -364,6 +372,42 @@ public class ProxyTunnellingTest
} }
} }
@Test
public void testExternalProxy() throws Exception
{
// Free proxy server obtained from http://hidemyass.com/proxy-list/
String proxyHost = "81.208.25.53";
int proxyPort = 3128;
try
{
new Socket(proxyHost, proxyPort).close();
}
catch (IOException x)
{
Assume.assumeNoException(x);
}
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.start();
HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setProxyConfiguration(new ProxyConfiguration(proxyHost, proxyPort));
httpClient.start();
try
{
ContentResponse response = httpClient.newRequest("https://www.google.com")
// Use a longer timeout, sometimes the proxy takes a while to answer
.timeout(20, TimeUnit.SECONDS)
.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
}
finally
{
httpClient.stop();
}
}
private static class ServerHandler extends AbstractHandler private static class ServerHandler extends AbstractHandler
{ {
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException