479678 - Support HTTP/1.1 Upgrade in HttpClient

+ Changing is upgrade test in HttpChannelOverHTTP
+ Adding wss to normalizePort / isDefaultPort
+ Adding wss to isSecure
+ Adding wss to proxy handling (for isSecure tests)
This commit is contained in:
Joakim Erdfelt 2015-10-14 11:14:48 -07:00
parent 45de46191b
commit f0deae82d4
5 changed files with 29 additions and 18 deletions

View File

@ -1044,12 +1044,20 @@ public class HttpClient extends ContainerLifeCycle
protected int normalizePort(String scheme, int port)
{
return port > 0 ? port : HttpScheme.HTTPS.is(scheme) ? 443 : 80;
if (port > 0)
return port;
else if (HttpScheme.HTTPS.is(scheme) || HttpScheme.WSS.is(scheme))
return 443;
else
return 80;
}
public boolean isDefaultPort(String scheme, int port)
{
return HttpScheme.HTTPS.is(scheme) ? port == 443 : port == 80;
if (HttpScheme.HTTPS.is(scheme) || HttpScheme.WSS.is(scheme))
return port == 443;
else
return port == 80;
}
@Override

View File

@ -76,7 +76,7 @@ public abstract class HttpDestination extends ContainerLifeCycle implements Dest
}
else
{
if (HttpScheme.HTTPS.is(getScheme()))
if (HttpScheme.HTTPS.is(getScheme())||HttpScheme.WSS.is(getScheme()))
connectionFactory = newSslClientConnectionFactory(connectionFactory);
}
this.connectionFactory = connectionFactory;

View File

@ -107,7 +107,7 @@ public class HttpProxy extends ProxyConfiguration.Proxy
public void succeeded(Connection connection)
{
HttpDestination destination = (HttpDestination)context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY);
if (HttpScheme.HTTPS.is(destination.getScheme()))
if (HttpScheme.HTTPS.is(destination.getScheme()) || HttpScheme.WSS.is(destination.getScheme()))
{
SslContextFactory sslContextFactory = destination.getHttpClient().getSslContextFactory();
if (sslContextFactory != null)

View File

@ -196,7 +196,7 @@ public class Socks4Proxy extends ProxyConfiguration.Proxy
HttpDestination destination = (HttpDestination)context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY);
HttpClient client = destination.getHttpClient();
ClientConnectionFactory connectionFactory = this.connectionFactory;
if (HttpScheme.HTTPS.is(destination.getScheme()))
if (HttpScheme.HTTPS.is(destination.getScheme()) || HttpScheme.WSS.is(destination.getScheme()))
connectionFactory = new SslClientConnectionFactory(client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory);
org.eclipse.jetty.io.Connection connection = connectionFactory.newConnection(getEndPoint(), context);
ClientConnectionFactory.Helper.replaceConnection(this, connection);

View File

@ -95,21 +95,24 @@ public class HttpChannelOverHTTP extends HttpChannel
return result;
HttpResponse response = exchange.getResponse();
if (response.getStatus() != HttpStatus.SWITCHING_PROTOCOLS_101)
return result;
// TODO: protocol version and connection: upgrade
HttpRequest request = exchange.getRequest();
if (request instanceof HttpConnectionUpgrader)
if ( (response.getVersion() == HttpVersion.HTTP_1_1) &&
(response.getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101) &&
(response.getHeaders().get("Connection").equalsIgnoreCase("upgrade")) )
{
HttpConnectionUpgrader listener = (HttpConnectionUpgrader)request;
try
// Upgrade Response
HttpRequest request = exchange.getRequest();
if (request instanceof HttpConnectionUpgrader)
{
listener.upgrade(response, getHttpConnection());
}
catch (Throwable x)
{
return new Result(result, x);
HttpConnectionUpgrader listener = (HttpConnectionUpgrader)request;
try
{
listener.upgrade(response, getHttpConnection());
}
catch (Throwable x)
{
return new Result(result, x);
}
}
}