Package org.microproxy
Interface ActivityTracker
- All Known Implementing Classes:
ActivityLogger,ActivityTrackerAdapter
public interface ActivityTracker
Observes proxy activity, e.g. for metrics or access logs. Callbacks run on the connection's
virtual thread and should be quick; every method has a no-op default.
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidbytesReceivedFromClient(FlowContext flowContext, int numberOfBytes) Called after bytes are read from the client.default voidbytesReceivedFromServer(FullFlowContext flowContext, int numberOfBytes) Called after bytes are read from the server.default voidbytesSentToClient(FlowContext flowContext, int numberOfBytes) Called after bytes are written to the client.default voidbytesSentToServer(FullFlowContext flowContext, int numberOfBytes) Called after bytes are written to the server.default voidclientConnected(FlowContext flowContext) Called when the proxy accepts a client connection.default voidclientDisconnected(FlowContext flowContext, SSLSession sslSession) Called when the client connection closes.default voidclientSSLHandshakeStarted(FlowContext flowContext) Called before the TLS handshake with the client starts.default voidclientSSLHandshakeSucceeded(FlowContext flowContext, SSLSession sslSession) Called after the TLS handshake with the client succeeds.default voidconnectionExceptionCaught(FlowContext flowContext, Throwable cause) Called when something failed on the client side of a flow: client I/O errors, and unexpected exceptions while serving the connection (which is then closed).default voidconnectionTimedOut(FlowContext flowContext) Called when the client connection reaches its idle timeout.default voidflowEnded(FlowRecord record) Called once when an exchange or a flow is over, with what an access log needs to know about it: an HTTP exchange whose response has been written or that was abandoned (afterresponseCompleted(org.microproxy.FlowContext, org.microproxy.http.HttpResponse), when that was called), and aCONNECTtunnel, a SOCKS client's tunnel, a WebSocket session, a TCP-hook tunnel, a CONNECT-UDP flow, or a transparent QUIC flow that was relayed or intercepted stream by stream, when it closes.default voidrequestReceivedFromClient(FlowContext flowContext, HttpRequest httpRequest) Called when a request head arrives from the client.default voidrequestSentToServer(FullFlowContext flowContext, HttpRequest httpRequest) Called when a request head is sent to the server.default voidresponseCompleted(FlowContext flowContext, HttpResponse httpResponse) Called when the whole response to a request, body included, has been written to the client (for aCONNECTor a protocol upgrade: once the response head has, before the tunnel starts).default voidresponseReceivedFromServer(FullFlowContext flowContext, HttpResponse httpResponse) Called when a response head arrives from the server.default voidresponseSentToClient(FlowContext flowContext, HttpResponse httpResponse) Called when a response head is sent to the client.default voidresponseSentToClient(FlowContext flowContext, HttpResponse httpResponse, ResponseSource source) Called when a response head has been sent to the client, with where the response came from.default voidserverConnected(FullFlowContext flowContext, InetSocketAddress serverAddress) Called when the proxy connects to a server.default voidserverConnectionExceptionCaught(FullFlowContext serverContext, Throwable cause) Called once for each failure on the server side of a flow: a failed connection attempt (unresolved name, refused or timed-out connect, failed TLS handshake, a chained proxy that refused; with several chained proxies, once per proxy tried), a server that timed out or answered badly, or an unexpected exception while a server connection was in use (also reported toconnectionExceptionCaught(org.microproxy.FlowContext, java.lang.Throwable), as the client connection closes too).default voidserverDisconnected(FullFlowContext flowContext, InetSocketAddress serverAddress) Called when the server connection closes.default voidtlsHandshakeFailed(FlowContext flowContext, boolean clientSide, Throwable cause) Called when a TLS handshake failed or timed out, before the failure is handled.default voidtransparentQuicFlowDecided(FlowContext flowContext, ClientHello clientHello, boolean intercepted, String reason) Called when the transparent QUIC listener (HttpProxyServerBootstrap.withTransparentQuicPort(int)) has decided what to do with a new client flow, from its ClientHello: intercept it (its HTTP/3 requests then come as for any client), or relay its datagrams to the server untouched.
-
Method Details
-
clientConnected
Called when the proxy accepts a client connection.- Parameters:
flowContext- the client connection or exchange context
-
clientSSLHandshakeStarted
Called before the TLS handshake with the client starts.- Parameters:
flowContext- the client connection or exchange context
-
clientSSLHandshakeSucceeded
Called after the TLS handshake with the client succeeds.- Parameters:
flowContext- the client connection or exchange contextsslSession- the client TLS session, ornullfor a plaintext connection
-
tlsHandshakeFailed
Called when a TLS handshake failed or timed out, before the failure is handled.- Parameters:
flowContext- the client's context for a handshake with the client (the TLS listener or an intercepted session); for one with a server or a TLS chained proxy, aFullFlowContextnaming itclientSide- whether the handshake was with the clientcause- the handshake's error, e.g. anSSLHandshakeExceptionor aSocketTimeoutException
-
clientDisconnected
Called when the client connection closes.- Parameters:
flowContext- the client connection or exchange contextsslSession- the client TLS session, ornullfor a plaintext connection
-
bytesReceivedFromClient
Called after bytes are read from the client.- Parameters:
flowContext- the client connection or exchange contextnumberOfBytes- the number of bytes transferred
-
requestReceivedFromClient
Called when a request head arrives from the client.- Parameters:
flowContext- the client connection or exchange contexthttpRequest- the request head
-
bytesSentToServer
Called after bytes are written to the server.- Parameters:
flowContext- the server connection contextnumberOfBytes- the number of bytes transferred
-
requestSentToServer
Called when a request head is sent to the server.- Parameters:
flowContext- the server connection contexthttpRequest- the request head
-
bytesReceivedFromServer
Called after bytes are read from the server.- Parameters:
flowContext- the server connection contextnumberOfBytes- the number of bytes transferred
-
responseReceivedFromServer
Called when a response head arrives from the server.- Parameters:
flowContext- the server connection contexthttpResponse- the response head
-
bytesSentToClient
Called after bytes are written to the client.- Parameters:
flowContext- the client connection or exchange contextnumberOfBytes- the number of bytes transferred
-
responseSentToClient
Called when a response head is sent to the client.- Parameters:
flowContext- the client connection or exchange contexthttpResponse- the response head
-
responseSentToClient
default void responseSentToClient(FlowContext flowContext, HttpResponse httpResponse, ResponseSource source) Called when a response head has been sent to the client, with where the response came from. The default callsresponseSentToClient(FlowContext, HttpResponse), so override one or the other. The status the server sent, if any, isFlowContext.upstreamStatus().- Parameters:
flowContext- the client connection or exchange contexthttpResponse- the response headsource- where the response originated
-
responseCompleted
Called when the whole response to a request, body included, has been written to the client (for aCONNECTor a protocol upgrade: once the response head has, before the tunnel starts).FlowContext.timings()is complete then. Not called when the exchange is abandoned half-way, e.g. because the server or the client failed.- Parameters:
flowContext- the client connection or exchange contexthttpResponse- the response head
-
flowEnded
Called once when an exchange or a flow is over, with what an access log needs to know about it: an HTTP exchange whose response has been written or that was abandoned (afterresponseCompleted(org.microproxy.FlowContext, org.microproxy.http.HttpResponse), when that was called), and aCONNECTtunnel, a SOCKS client's tunnel, a WebSocket session, a TCP-hook tunnel, a CONNECT-UDP flow, or a transparent QUIC flow that was relayed or intercepted stream by stream, when it closes.FlowRecord.context()'sFlowContext.failure()andFlowContext.responseFlags()are final then.- Parameters:
record- the finished exchange or flow
-
serverConnected
Called when the proxy connects to a server.- Parameters:
flowContext- the server connection contextserverAddress- the connected server address
-
serverDisconnected
Called when the server connection closes.- Parameters:
flowContext- the server connection contextserverAddress- the connected server address
-
connectionTimedOut
Called when the client connection reaches its idle timeout.- Parameters:
flowContext- the client connection or exchange context
-
connectionExceptionCaught
Called when something failed on the client side of a flow: client I/O errors, and unexpected exceptions while serving the connection (which is then closed).- Parameters:
flowContext- the client connection or exchange contextcause- the failure that triggered this event
-
serverConnectionExceptionCaught
Called once for each failure on the server side of a flow: a failed connection attempt (unresolved name, refused or timed-out connect, failed TLS handshake, a chained proxy that refused; with several chained proxies, once per proxy tried), a server that timed out or answered badly, or an unexpected exception while a server connection was in use (also reported toconnectionExceptionCaught(org.microproxy.FlowContext, java.lang.Throwable), as the client connection closes too).serverContextnames the server or chained proxy; its remote address isnullwhen the name did not resolve. A keep-alive connection that turned out to be closed, and is retried transparently, is not reported.- Parameters:
serverContext- the server connection contextcause- the failure that triggered this event
-
transparentQuicFlowDecided
default void transparentQuicFlowDecided(FlowContext flowContext, ClientHello clientHello, boolean intercepted, String reason) Called when the transparent QUIC listener (HttpProxyServerBootstrap.withTransparentQuicPort(int)) has decided what to do with a new client flow, from its ClientHello: intercept it (its HTTP/3 requests then come as for any client), or relay its datagrams to the server untouched.clientConnected(org.microproxy.FlowContext)came before, with the same context;clientDisconnected(org.microproxy.FlowContext, javax.net.ssl.SSLSession)comes when the flow ends.- Parameters:
flowContext- the flow's context, whoseFlowContext.isTransparentQuic()is trueclientHello- the ClientHello the client sent in its Initial packetsintercepted- whether the proxy intercepts the flow; false when it relays itreason- why the flow is relayed (an ignored host, no HTTP/3 offered, a filter declined, ...), ornullwhen it is intercepted
-