412846 - jetty Http Client Connection through Proxy is failing with Timeout.

The problem was due to the fact that the server replied with HTTP/1.0
to the CONNECT request; because of this, the parser was not set in the
"head response mode".

Now we are setting the parser in the head response mode also if the
request method is a CONNECT.
This commit is contained in:
Simone Bordet 2013-07-25 16:38:22 +02:00
commit 743c78cc0c
2 changed files with 50 additions and 5 deletions

View File

@ -147,7 +147,8 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
HttpConversation conversation = exchange.getConversation();
HttpResponse response = exchange.getResponse();
parser.setHeadResponse(HttpMethod.HEAD.is(exchange.getRequest().method()));
String method = exchange.getRequest().method();
parser.setHeadResponse(HttpMethod.HEAD.is(method) || HttpMethod.CONNECT.is(method));
response.version(version).status(status).reason(reason);
// Probe the protocol handlers

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.proxy;
import java.io.IOException;
import java.net.ConnectException;
import java.net.Socket;
import java.net.URLEncoder;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
@ -55,6 +56,7 @@ import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
@ -116,14 +118,20 @@ public class ProxyTunnellingTest
protected void stopServer() throws Exception
{
server.stop();
server.join();
if (server != null)
{
server.stop();
server.join();
}
}
protected void stopProxy() throws Exception
{
proxy.stop();
proxy.join();
if (proxy != null)
{
proxy.stop();
proxy.join();
}
}
@Test
@ -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
{
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException