public interface HttpFilters
Interface for objects that filter HttpObjects, including both requests and responses, and informs of
different steps in request/response.
Multiple methods are defined, corresponding to different steps in the request processing lifecycle. Some of these methods is given the current object (request, response or chunk) and is allowed to modify it in place. Others provide a notification of when specific operations happen (i.e. connection in queue, DNS resolution, SSL handshaking and so forth).
Because HTTP transfers can be chunked, for any given request or response, the filter methods that can modify
request/response in place may be called multiple times, once for the initial HttpRequest or
HttpResponse, and once for each subsequent HttpContent. The last chunk will always be a
LastHttpContent and can be checked for being last using HttpProxyUtil.isLastChunk(HttpObject).
A new instance of HttpFilters is created for each request, so these objects can be stateful.
To monitor (and time measure?) the different steps the request/response goes through, many informative methods are provided. Those steps are reported in the following order:
| 限定符和类型 | 方法和说明 |
|---|---|
io.netty.handler.codec.http.HttpResponse |
clientToProxyRequest(io.netty.handler.codec.http.HttpObject httpObject)
Filters requests on their way from the client to the proxy.
|
io.netty.handler.codec.http.HttpObject |
proxyToClientResponse(io.netty.handler.codec.http.HttpObject httpObject)
Filters responses on their way from the proxy to the client.
|
void |
proxyToServerConnectionFailed(FullFlowContext flowContext)
Informs filter that proxy to server connection has failed.
|
void |
proxyToServerConnectionQueued(FullFlowContext flowContext)
Informs filter that proxy to server connection is in queue.
|
void |
proxyToServerConnectionSSLHandshakeStarted(FullFlowContext flowContext)
Informs filter that proxy to server ssl handshake is initiating.
|
void |
proxyToServerConnectionStarted(FullFlowContext flowContext)
Informs filter that proxy to server connection is initiating.
|
void |
proxyToServerConnectionSucceeded(FullFlowContext flowContext)
Informs filter that proxy to server connection has succeeded.
|
io.netty.handler.codec.http.HttpResponse |
proxyToServerRequest(io.netty.handler.codec.http.HttpObject httpObject)
Filters requests on their way from the proxy to the server.
|
void |
proxyToServerRequestSending(FullFlowContext flowContext,
io.netty.handler.codec.http.HttpRequest httpRequest) |
void |
proxyToServerRequestSent(FullFlowContext flowContext,
io.netty.handler.codec.http.LastHttpContent lastHttpContent) |
io.netty.handler.codec.http.HttpObject |
serverToProxyResponse(io.netty.handler.codec.http.HttpObject httpObject)
Filters responses on their way from the server to the proxy.
|
void |
serverToProxyResponseReceived(FullFlowContext flowContext)
Informs filter that server to proxy response has been received.
|
void |
serverToProxyResponseReceiving(FullFlowContext flowContext)
Informs filter that server to proxy response is being received.
|
void |
serverToProxyResponseTimedOut()
Informs filter that a timeout occurred before the server response was received by the client.
|
io.netty.handler.codec.http.HttpResponse clientToProxyRequest(io.netty.handler.codec.http.HttpObject httpObject)
Important: When returning a response, you must include a mechanism to allow the client to determine the length of the message (see RFC 7230, section 3.3.3: https://tools.ietf.org/html/rfc7230#section-3.3.3 ). For messages that may contain a body, you may do this by setting the Transfer-Encoding to chunked, setting an appropriate Content-Length, or by adding a "Connection: close" header to the response (which will instruct LittleProxy to close the connection). If the short-circuit response contains body content, it is recommended that you return a FullHttpResponse.
httpObject - Client to Proxy HttpRequest (and HttpContent, if chunked)io.netty.handler.codec.http.HttpResponse proxyToServerRequest(io.netty.handler.codec.http.HttpObject httpObject)
Important: When returning a response, you must include a mechanism to allow the client to determine the length of the message (see RFC 7230, section 3.3.3: https://tools.ietf.org/html/rfc7230#section-3.3.3 ). For messages that may contain a body, you may do this by setting the Transfer-Encoding to chunked, setting an appropriate Content-Length, or by adding a "Connection: close" header to the response. (which will instruct LittleProxy to close the connection). If the short-circuit response contains body content, it is recommended that you return a FullHttpResponse.
httpObject - Proxy to Server HttpRequest (and HttpContent, if chunked)void proxyToServerRequestSending(FullFlowContext flowContext, io.netty.handler.codec.http.HttpRequest httpRequest)
flowContext - provides contextual information about the flowhttpRequest - Informs filter that proxy to server request is being sent.void proxyToServerRequestSent(FullFlowContext flowContext, io.netty.handler.codec.http.LastHttpContent lastHttpContent)
flowContext - the ChannelHandlerContext used to connect to the serverlastHttpContent - Informs filter that the HTTP request, including any content, has been sent.io.netty.handler.codec.http.HttpObject serverToProxyResponse(io.netty.handler.codec.http.HttpObject httpObject)
httpObject - Server to Proxy HttpResponse (and HttpContent, if chunked)void serverToProxyResponseTimedOut()
HttpProxyManagerBootstrap.withIdleConnectionTimeout(int) for information on setting the timeout.void serverToProxyResponseReceiving(FullFlowContext flowContext)
flowContext - the ChannelHandlerContext used to connect to the servervoid serverToProxyResponseReceived(FullFlowContext flowContext)
flowContext - the ChannelHandlerContext used to connect to the serverio.netty.handler.codec.http.HttpObject proxyToClientResponse(io.netty.handler.codec.http.HttpObject httpObject)
httpObject - Proxy to Client HttpResponse (and HttpContent, if chunked)void proxyToServerConnectionQueued(FullFlowContext flowContext)
flowContext - the ChannelHandlerContext used to connect to the servervoid proxyToServerConnectionStarted(FullFlowContext flowContext)
flowContext - the ChannelHandlerContext used to connect to the servervoid proxyToServerConnectionSSLHandshakeStarted(FullFlowContext flowContext)
flowContext - the ChannelHandlerContext used to connect to the servervoid proxyToServerConnectionFailed(FullFlowContext flowContext)
flowContext - the ChannelHandlerContext used to connect to the servervoid proxyToServerConnectionSucceeded(FullFlowContext flowContext)
flowContext - the ChannelHandlerContext used to connect to the serverCopyright © 2022 Zodiac. All rights reserved.