Interface HttpFilters
-
- All Known Implementing Classes:
HttpFiltersAdapter
public interface HttpFiltersInterface 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
HttpRequestorHttpResponse, and once for each subsequentHttpContent. The last chunk will always be aLastHttpContentand can be checked for being last usingProxyUtils.isLastChunk(HttpObject).HttpFiltersSource.getMaximumRequestBufferSizeInBytes()andHttpFiltersSource.getMaximumResponseBufferSizeInBytes()can be used to instruct the proxy to buffer theHttpObjects sent to all of its request/response filters, in which case it will buffer up to the specified limit and then send either completeHttpRequests orHttpResponses to the filter methods. When buffering, if the proxy receives more data than fits in the specified maximum bytes to buffer, the proxy will stop processing the request and respond with a 502 Bad Gateway error.A new instance of
HttpFiltersis 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:
- clientToProxyRequest
- proxyToServerConnectionQueued
- proxyToServerResolutionStarted
- proxyToServerResolutionSucceeded
- proxyToServerRequest (can be multiple if chunked)
- proxyToServerConnectionStarted
- proxyToServerConnectionFailed (if connection couldn't be established)
- proxyToServerConnectionSSLHandshakeStarted (only if HTTPS required)
- proxyToServerConnectionSucceeded
- proxyToServerRequestSending
- proxyToServerRequestSent
- serverToProxyResponseReceiving
- serverToProxyResponse (can be multiple if chunked)
- serverToProxyResponseReceived
- proxyToClientResponse
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description HttpResponseclientToProxyRequest(HttpObject httpObject)Filters requests on their way from the client to the proxy.HttpObjectproxyToClientResponse(HttpObject httpObject)Filters responses on their way from the proxy to the client.booleanproxyToServerAllowMitm()Allow this proxy to act as an SSL man in the middle.voidproxyToServerConnectionFailed()Informs filter that proxy to server connection has failed.voidproxyToServerConnectionQueued()Informs filter that proxy to server connection is in queue.voidproxyToServerConnectionSSLHandshakeStarted()Informs filter that proxy to server ssl handshake is initiating.voidproxyToServerConnectionStarted()Informs filter that proxy to server connection is initiating.voidproxyToServerConnectionSucceeded(ChannelHandlerContext serverCtx)Informs filter that proxy to server connection has succeeded.HttpResponseproxyToServerRequest(HttpObject httpObject)Filters requests on their way from the proxy to the server.voidproxyToServerRequestSending()Informs filter that proxy to server request is being sent.voidproxyToServerRequestSent()Informs filter that the HTTP request, including any content, has been sent.voidproxyToServerResolutionFailed(String hostAndPort)Informs filter that proxy to server DNS resolution failed for the specified host and port.InetSocketAddressproxyToServerResolutionStarted(String resolvingServerHostAndPort)Filter DNS resolution from proxy to server.voidproxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress)Informs filter that proxy to server DNS resolution has happened.HttpObjectserverToProxyResponse(HttpObject httpObject)Filters responses on their way from the server to the proxy.voidserverToProxyResponseReceived()Informs filter that server to proxy response has been received.voidserverToProxyResponseReceiving()Informs filter that server to proxy response is being received.voidserverToProxyResponseTimedOut()Informs filter that a timeout occurred before the server response was received by the client.
-
-
-
Method Detail
-
clientToProxyRequest
HttpResponse clientToProxyRequest(HttpObject httpObject)
Filters requests on their way from the client to the proxy. To interrupt processing of this request and return a response to the client immediately, return an HttpResponse here. Otherwise, return null to continue processing as usual.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.
- Parameters:
httpObject- Client to Proxy HttpRequest (and HttpContent, if chunked)- Returns:
- a short-circuit response, or null to continue processing as usual
-
proxyToServerRequest
HttpResponse proxyToServerRequest(HttpObject httpObject)
Filters requests on their way from the proxy to the server. To interrupt processing of this request and return a response to the client immediately, return an HttpResponse here. Otherwise, return null to continue processing as usual.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.
- Parameters:
httpObject- Proxy to Server HttpRequest (and HttpContent, if chunked)- Returns:
- a short-circuit response, or null to continue processing as usual
-
proxyToServerRequestSending
void proxyToServerRequestSending()
Informs filter that proxy to server request is being sent.
-
proxyToServerRequestSent
void proxyToServerRequestSent()
Informs filter that the HTTP request, including any content, has been sent.
-
serverToProxyResponse
HttpObject serverToProxyResponse(HttpObject httpObject)
Filters responses on their way from the server to the proxy.- Parameters:
httpObject- Server to Proxy HttpResponse (and HttpContent, if chunked)- Returns:
- the modified (or unmodified) HttpObject. Returning null will force a disconnect.
-
serverToProxyResponseTimedOut
void serverToProxyResponseTimedOut()
Informs filter that a timeout occurred before the server response was received by the client. The timeout may have occurred while the client was sending the request, waiting for a response, or after the client started receiving a response (i.e. if the response from the server "stalls"). SeeHttpProxyServerBootstrap.withIdleConnectionTimeout(int)for information on setting the timeout.
-
serverToProxyResponseReceiving
void serverToProxyResponseReceiving()
Informs filter that server to proxy response is being received.
-
serverToProxyResponseReceived
void serverToProxyResponseReceived()
Informs filter that server to proxy response has been received.
-
proxyToClientResponse
HttpObject proxyToClientResponse(HttpObject httpObject)
Filters responses on their way from the proxy to the client.- Parameters:
httpObject- Proxy to Client HttpResponse (and HttpContent, if chunked)- Returns:
- the modified (or unmodified) HttpObject. Returning null will force a disconnect.
-
proxyToServerConnectionQueued
void proxyToServerConnectionQueued()
Informs filter that proxy to server connection is in queue.
-
proxyToServerResolutionStarted
InetSocketAddress proxyToServerResolutionStarted(String resolvingServerHostAndPort)
Filter DNS resolution from proxy to server.- Parameters:
resolvingServerHostAndPort- Server "HOST:PORT"- Returns:
- alternative address resolution. Returning null will let normal DNS resolution continue.
-
proxyToServerResolutionFailed
void proxyToServerResolutionFailed(String hostAndPort)
Informs filter that proxy to server DNS resolution failed for the specified host and port.- Parameters:
hostAndPort- hostname and port the proxy failed to resolve
-
proxyToServerResolutionSucceeded
void proxyToServerResolutionSucceeded(String serverHostAndPort, InetSocketAddress resolvedRemoteAddress)
Informs filter that proxy to server DNS resolution has happened.- Parameters:
serverHostAndPort- Server "HOST:PORT"resolvedRemoteAddress- Address it was proxyToServerResolutionSucceeded to
-
proxyToServerConnectionStarted
void proxyToServerConnectionStarted()
Informs filter that proxy to server connection is initiating.
-
proxyToServerConnectionSSLHandshakeStarted
void proxyToServerConnectionSSLHandshakeStarted()
Informs filter that proxy to server ssl handshake is initiating.
-
proxyToServerConnectionFailed
void proxyToServerConnectionFailed()
Informs filter that proxy to server connection has failed.
-
proxyToServerConnectionSucceeded
void proxyToServerConnectionSucceeded(ChannelHandlerContext serverCtx)
Informs filter that proxy to server connection has succeeded.- Parameters:
serverCtx- theChannelHandlerContextused to connect to the server
-
proxyToServerAllowMitm
boolean proxyToServerAllowMitm()
Allow this proxy to act as an SSL man in the middle.Has no impact if man in the middle is not enabled.
- Returns:
- true to allow mitm, false to not mitm the proxy to server connection.
-
-