Top Description Inners Fields Constructors Methods
io.netty.handler.proxy

public final Class HttpProxyHandler

extends ProxyHandler
Class Inheritance
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.ChannelHandlerContext, .ChannelInboundHandler, .ChannelOutboundHandler, .ChannelPipeline, .ChannelPromise, io.netty.handler.codec.base64.Base64, io.netty.handler.codec.http.DefaultFullHttpRequest, .FullHttpRequest, .HttpClientCodec, .HttpHeaderNames, .HttpHeaders, .DefaultHttpHeadersFactory, .HttpHeadersFactory, .HttpMethod, .HttpResponse, .HttpResponseStatus, .HttpUtil, .HttpVersion, .LastHttpContent, io.netty.util.AsciiString, .CharsetUtil, io.netty.util.internal.ObjectUtil, java.net.InetSocketAddress, .SocketAddress

Handler that establishes a blind forwarding proxy tunnel using HTTP/1.1 CONNECT request. It can be used to establish plaintext or secure tunnels.

HTTP users who need to connect to a message-forwarding HTTP proxy agent instead of a tunneling proxy should not use this handler.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
HttpProxyHandler.HttpProxyConnectException

Specific case of a connection failure, which may include headers from the proxy.

Field Summary

Modifier and TypeField and Description
private static final String
private final CharSequence
private final HttpProxyHandler.HttpClientCodecWrapper
private final boolean
private HttpHeaders
private final HttpHeaders
private final String
private static final String
private HttpResponseStatus
private final String
Inherited from io.netty.handler.proxy.ProxyHandler:
AUTH_NONE

Constructor Summary

AccessConstructor and Description
public
public
public
HttpProxyHandler(SocketAddress proxyAddress, HttpHeaders headers, boolean ignoreDefaultPortsInConnectHostHeader)

public
HttpProxyHandler(SocketAddress proxyAddress, String username, String password)

public
HttpProxyHandler(SocketAddress proxyAddress, String username, String password, HttpHeaders headers)

public
HttpProxyHandler(SocketAddress proxyAddress, String username, String password, HttpHeaders headers, boolean ignoreDefaultPortsInConnectHostHeader)

Method Summary

Modifier and TypeMethod and Description
protected void
addCodec(ChannelHandlerContext ctx)

Implements abstract io.netty.handler.proxy.ProxyHandler.addCodec.

Adds the codec handlers required to communicate with the proxy server.
public String
authScheme()

Implements abstract io.netty.handler.proxy.ProxyHandler.authScheme.

Returns the name of the authentication scheme in use.
protected boolean
handleResponse(ChannelHandlerContext ctx, Object response)

Implements abstract io.netty.handler.proxy.ProxyHandler.handleResponse.

Handles the message received from the proxy server.
protected Object
newInitialMessage(ChannelHandlerContext ctx)

Implements abstract io.netty.handler.proxy.ProxyHandler.newInitialMessage.

Returns a new message that is sent at first time when the connection to the proxy server has been established.
public String
public String
protocol()

Implements abstract io.netty.handler.proxy.ProxyHandler.protocol.

Returns the name of the proxy protocol in use.
protected void
protected void
public String
Inherited from io.netty.handler.proxy.ProxyHandler:
channelActivechannelInactivechannelReadchannelReadCompleteconnectconnectFutureconnectTimeoutMillisdestinationAddressexceptionCaughtexceptionMessageflushhandlerAddedisConnectedproxyAddresssendToProxyServersetConnectTimeoutMilliswrite

Field Detail

AUTH_BASICback to summary
private static final String AUTH_BASIC
authorizationback to summary
private final CharSequence authorization
codecWrapperback to summary
private final HttpProxyHandler.HttpClientCodecWrapper codecWrapper
ignoreDefaultPortsInConnectHostHeaderback to summary
private final boolean ignoreDefaultPortsInConnectHostHeader
inboundHeadersback to summary
private HttpHeaders inboundHeaders
outboundHeadersback to summary
private final HttpHeaders outboundHeaders
passwordback to summary
private final String password
PROTOCOLback to summary
private static final String PROTOCOL
statusback to summary
private HttpResponseStatus status
usernameback to summary
private final String username

Constructor Detail

HttpProxyHandlerback to summary
public HttpProxyHandler(SocketAddress proxyAddress)
HttpProxyHandlerback to summary
public HttpProxyHandler(SocketAddress proxyAddress, HttpHeaders headers)
HttpProxyHandlerback to summary
public HttpProxyHandler(SocketAddress proxyAddress, HttpHeaders headers, boolean ignoreDefaultPortsInConnectHostHeader)
HttpProxyHandlerback to summary
public HttpProxyHandler(SocketAddress proxyAddress, String username, String password)
HttpProxyHandlerback to summary
public HttpProxyHandler(SocketAddress proxyAddress, String username, String password, HttpHeaders headers)
HttpProxyHandlerback to summary
public HttpProxyHandler(SocketAddress proxyAddress, String username, String password, HttpHeaders headers, boolean ignoreDefaultPortsInConnectHostHeader)

Method Detail

addCodecback to summary
protected void addCodec(ChannelHandlerContext ctx) throws Exception

Implements abstract io.netty.handler.proxy.ProxyHandler.addCodec.

Doc from io.netty.handler.proxy.ProxyHandler.addCodec.

Adds the codec handlers required to communicate with the proxy server.

Annotations
@Override
authSchemeback to summary
public String authScheme()

Implements abstract io.netty.handler.proxy.ProxyHandler.authScheme.

Doc from io.netty.handler.proxy.ProxyHandler.authScheme.

Returns the name of the authentication scheme in use.

Annotations
@Override
handleResponseback to summary
protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception

Implements abstract io.netty.handler.proxy.ProxyHandler.handleResponse.

Doc from io.netty.handler.proxy.ProxyHandler.handleResponse.

Handles the message received from the proxy server.

Returns:boolean

true if the connection to the destination has been established, false if the connection to the destination has not been established and more messages are expected from the proxy server

Annotations
@Override
newInitialMessageback to summary
protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception

Implements abstract io.netty.handler.proxy.ProxyHandler.newInitialMessage.

Doc from io.netty.handler.proxy.ProxyHandler.newInitialMessage.

Returns a new message that is sent at first time when the connection to the proxy server has been established.

Returns:Object

the initial message, or null if the proxy server is expected to send the first message instead

Annotations
@Override
passwordback to summary
public String password()
protocolback to summary
public String protocol()

Implements abstract io.netty.handler.proxy.ProxyHandler.protocol.

Doc from io.netty.handler.proxy.ProxyHandler.protocol.

Returns the name of the proxy protocol in use.

Annotations
@Override
removeDecoderback to summary
protected void removeDecoder(ChannelHandlerContext ctx) throws Exception

Implements abstract io.netty.handler.proxy.ProxyHandler.removeDecoder.

Doc from io.netty.handler.proxy.ProxyHandler.removeDecoder.

Removes the decoders added in addCodec(ChannelHandlerContext).

Annotations
@Override
removeEncoderback to summary
protected void removeEncoder(ChannelHandlerContext ctx) throws Exception

Implements abstract io.netty.handler.proxy.ProxyHandler.removeEncoder.

Doc from io.netty.handler.proxy.ProxyHandler.removeEncoder.

Removes the encoders added in addCodec(ChannelHandlerContext).

Annotations
@Override
usernameback to summary
public String username()
io.netty.handler.proxy back to summary

private final Class HttpProxyHandler.HttpClientCodecWrapper

extends Object
implements ChannelInboundHandler, ChannelOutboundHandler
Class Inheritance
  • java.lang.Object
  • io.netty.handler.proxy.HttpProxyHandler.HttpClientCodecWrapper
All Implemented Interfaces
io.netty.channel.ChannelOutboundHandler, io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

Field Summary

Modifier and TypeField and Description
pack-priv final HttpClientCodec

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
bind(ChannelHandlerContext
the ChannelHandlerContext for which the bind operation is made
ctx
,
SocketAddress
the SocketAddress to which it should bound
localAddress
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.bind.

Called once a bind operation is made.
public void
public void
channelInactive(ChannelHandlerContext ctx)

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
public void
channelRead(ChannelHandlerContext ctx, Object msg)

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Invoked when the current Channel has read a message from the peer.
public void
channelReadComplete(ChannelHandlerContext ctx)

Implements io.netty.channel.ChannelInboundHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object).
public void
public void
public void
public void
close(ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.close.

Called once a close operation is made.
public void
connect(ChannelHandlerContext
the ChannelHandlerContext for which the connect operation is made
ctx
,
SocketAddress
the SocketAddress to which it should connect
remoteAddress
,
SocketAddress
the SocketAddress which is used as source on connect
localAddress
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.connect.

Called once a connect operation is made.
public void
deregister(ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.
public void
disconnect(ChannelHandlerContext
the ChannelHandlerContext for which the disconnect operation is made
ctx
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.disconnect.

Called once a disconnect operation is made.
public void
public void
flush(ChannelHandlerContext
the ChannelHandlerContext for which the flush operation is made
ctx
)

Implements io.netty.channel.ChannelOutboundHandler.flush.

Called once a flush operation is made.
public void
handlerAdded(ChannelHandlerContext ctx)

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public void
handlerRemoved(ChannelHandlerContext ctx)

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
public void
public void
userEventTriggered(ChannelHandlerContext ctx, Object evt)

Implements io.netty.channel.ChannelInboundHandler.userEventTriggered.

Gets called if an user event was triggered.
public void
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Implements io.netty.channel.ChannelOutboundHandler.write.

Called once a write operation is made.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

codecback to summary
pack-priv final HttpClientCodec codec

Constructor Detail

HttpClientCodecWrapperback to summary
private HttpClientCodecWrapper()

Method Detail

bindback to summary
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.bind.

Doc from io.netty.channel.ChannelOutboundHandler.bind.

Called once a bind operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the bind operation is made

localAddress:SocketAddress

the SocketAddress to which it should bound

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
channelActiveback to summary
public void channelActive(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelInboundHandler.channelActive.

Doc from io.netty.channel.ChannelInboundHandler.channelActive.

The Channel of the ChannelHandlerContext is now active

Annotations
@Override
channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelInboundHandler.channelInactive.

Doc from io.netty.channel.ChannelInboundHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Annotations
@Override
channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandler.channelRead.

Invoked when the current Channel has read a message from the peer.

Annotations
@Override
channelReadCompleteback to summary
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelInboundHandler.channelReadComplete.

Doc from io.netty.channel.ChannelInboundHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object). If ChannelOption#AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelHandlerContext#read() is called.

Annotations
@Override
channelRegisteredback to summary
public void channelRegistered(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelInboundHandler.channelRegistered.

Doc from io.netty.channel.ChannelInboundHandler.channelRegistered.

The Channel of the ChannelHandlerContext was registered with its EventLoop

Annotations
@Override
channelUnregisteredback to summary
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelInboundHandler.channelUnregistered.

Doc from io.netty.channel.ChannelInboundHandler.channelUnregistered.

The Channel of the ChannelHandlerContext was unregistered from its EventLoop

Annotations
@Override
channelWritabilityChangedback to summary
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelInboundHandler.channelWritabilityChanged.

Doc from io.netty.channel.ChannelInboundHandler.channelWritabilityChanged.

Gets called once the writable state of a Channel changed. You can check the state with Channel#isWritable().

Annotations
@Override
closeback to summary
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.close.

Doc from io.netty.channel.ChannelOutboundHandler.close.

Called once a close operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
connectback to summary
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.connect.

Doc from io.netty.channel.ChannelOutboundHandler.connect.

Called once a connect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

the SocketAddress to which it should connect

localAddress:SocketAddress

the SocketAddress which is used as source on connect

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
deregisterback to summary
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.deregister.

Doc from io.netty.channel.ChannelOutboundHandler.deregister.

Called once a deregister operation is made from the current registered EventLoop.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
disconnectback to summary
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.disconnect.

Doc from io.netty.channel.ChannelOutboundHandler.disconnect.

Called once a disconnect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the disconnect operation is made

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
exceptionCaughtback to summary
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Implements io.netty.channel.ChannelInboundHandler.exceptionCaught, io.netty.channel.ChannelHandler.exceptionCaught.

Doc from io.netty.channel.ChannelInboundHandler.exceptionCaught.

Gets called if a Throwable was thrown.

Annotations
@Override
flushback to summary
public void flush(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.flush.

Doc from io.netty.channel.ChannelOutboundHandler.flush.

Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the flush operation is made

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelHandler.handlerRemoved.

Doc from io.netty.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
readback to summary
public void read(ChannelHandlerContext ctx) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.read.

Doc from io.netty.channel.ChannelOutboundHandler.read.

Intercepts ChannelHandlerContext#read().

Annotations
@Override
userEventTriggeredback to summary
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception

Implements io.netty.channel.ChannelInboundHandler.userEventTriggered.

Doc from io.netty.channel.ChannelInboundHandler.userEventTriggered.

Gets called if an user event was triggered.

Annotations
@Override
writeback to summary
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception

Implements io.netty.channel.ChannelOutboundHandler.write.

Doc from io.netty.channel.ChannelOutboundHandler.write.

Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel#flush() is called

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the write operation is made

msg:Object

the message to write

promise:ChannelPromise

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:
thrown if an error occurs
io.netty.handler.proxy back to summary

public final Class HttpProxyHandler.HttpProxyConnectException

extends ProxyConnectException
Class Inheritance

Specific case of a connection failure, which may include headers from the proxy.

Field Summary

Modifier and TypeField and Description
private final HttpHeaders
private static final long

Constructor Summary

AccessConstructor and Description
public
HttpProxyConnectException(String
The failure message.
message
,
HttpHeaders
Header associated with the connection failure. May be null.
headers
)

Method Summary

Modifier and TypeMethod and Description
public HttpHeaders
headers()

Returns headers, if any.

Field Detail

headersback to summary
private final HttpHeaders headers
serialVersionUIDback to summary
private static final long serialVersionUID

Hides io.netty.handler.proxy.ProxyConnectException.serialVersionUID.

Constructor Detail

HttpProxyConnectExceptionback to summary
public HttpProxyConnectException(String message, HttpHeaders headers)
Parameters
message:String

The failure message.

headers:HttpHeaders

Header associated with the connection failure. May be null.

Method Detail

headersback to summary
public HttpHeaders headers()

Returns headers, if any. May be null.