allow InetSocketAddress to be translated in ConnectHandler

This commit is contained in:
Greg Wilkins 2015-02-06 11:17:36 +11:00
parent d08fced010
commit 21e8cf68b6
1 changed files with 16 additions and 5 deletions

View File

@ -251,16 +251,13 @@ public class ConnectHandler extends HandlerWrapper
SocketChannel channel = SocketChannel.open(); SocketChannel channel = SocketChannel.open();
channel.socket().setTcpNoDelay(true); channel.socket().setTcpNoDelay(true);
channel.configureBlocking(false); channel.configureBlocking(false);
InetSocketAddress address = new InetSocketAddress(host, port);
AsyncContext asyncContext = request.startAsync(); AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(0); asyncContext.setTimeout(0);
if (LOG.isDebugEnabled())
LOG.debug("Connecting to {}", address);
HttpTransport transport = baseRequest.getHttpChannel().getHttpTransport(); HttpTransport transport = baseRequest.getHttpChannel().getHttpTransport();
// TODO Handle CONNECT over HTTP2!
if (!(transport instanceof HttpConnection)) if (!(transport instanceof HttpConnection))
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -268,7 +265,10 @@ public class ConnectHandler extends HandlerWrapper
sendConnectResponse(request, response, HttpServletResponse.SC_FORBIDDEN); sendConnectResponse(request, response, HttpServletResponse.SC_FORBIDDEN);
return; return;
} }
InetSocketAddress address = newConnectAddress(host, port);
if (LOG.isDebugEnabled())
LOG.debug("Connecting to {}", address);
ConnectContext connectContext = new ConnectContext(request, response, asyncContext, (HttpConnection)transport); ConnectContext connectContext = new ConnectContext(request, response, asyncContext, (HttpConnection)transport);
if (channel.connect(address)) if (channel.connect(address))
selector.accept(channel, connectContext); selector.accept(channel, connectContext);
@ -281,6 +281,17 @@ public class ConnectHandler extends HandlerWrapper
} }
} }
/* ------------------------------------------------------------ */
/** Create the address the connect channel will connect to.
* @param host The host from the connect request
* @param port The port from the connect request
* @return The InetSocketAddress to connect to.
*/
protected InetSocketAddress newConnectAddress(String host, int port)
{
return new InetSocketAddress(host, port);
}
protected void onConnectSuccess(ConnectContext connectContext, UpstreamConnection upstreamConnection) protected void onConnectSuccess(ConnectContext connectContext, UpstreamConnection upstreamConnection)
{ {
HttpConnection httpConnection = connectContext.getHttpConnection(); HttpConnection httpConnection = connectContext.getHttpConnection();