diff --git a/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java b/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java index f16797233..31bc66a47 100644 --- a/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java +++ b/src/main/java/org/littleshoot/proxy/impl/ClientToProxyConnection.java @@ -20,6 +20,7 @@ import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.traffic.GlobalTrafficShapingHandler; +import io.netty.util.AttributeKey; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import org.apache.commons.codec.binary.Base64; @@ -89,6 +90,11 @@ public class ClientToProxyConnection extends ProxyConnection { * Used for case-insensitive comparisons when checking direct proxy request. */ private static final Pattern HTTP_SCHEME = Pattern.compile("^http://.*", Pattern.CASE_INSENSITIVE); + + /** + * Context attribute key for username + */ + private static final AttributeKey ATTR_USERNAME = AttributeKey.valueOf("username"); /** * Keep track of all ProxyToServerConnections by host+port. @@ -973,6 +979,10 @@ private boolean authenticationRequired(HttpRequest request) { LOG.debug(authentication); request.headers().remove(HttpHeaders.Names.PROXY_AUTHORIZATION); authenticated.set(true); + + //Save username for filtering based on user + ctx.attr(ATTR_USERNAME).set(userName); + return false; }