diff --git a/zuul-core/src/main/java/com/netflix/zuul/netty/server/http2/Http2StreamInitializer.java b/zuul-core/src/main/java/com/netflix/zuul/netty/server/http2/Http2StreamInitializer.java index 2a55b763f2..689d580329 100644 --- a/zuul-core/src/main/java/com/netflix/zuul/netty/server/http2/Http2StreamInitializer.java +++ b/zuul-core/src/main/java/com/netflix/zuul/netty/server/http2/Http2StreamInitializer.java @@ -22,6 +22,7 @@ import com.netflix.netty.common.metrics.Http2MetricsChannelHandlers; import com.netflix.netty.common.proxyprotocol.HAProxyMessageChannelHandler; import com.netflix.zuul.netty.server.BaseZuulChannelInitializer; +import com.netflix.zuul.netty.server.Server; import com.netflix.zuul.netty.server.ssl.SslHandshakeInfoHandler; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; @@ -30,6 +31,8 @@ import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http2.Http2StreamFrameToHttpObjectCodec; import io.netty.util.AttributeKey; + +import java.util.Set; import java.util.function.Consumer; /** @@ -38,6 +41,23 @@ @ChannelHandler.Sharable public class Http2StreamInitializer extends ChannelInboundHandlerAdapter { + private static final Set<AttributeKey<?>> ATTRIBUTES_TO_COPY = Set.of( + SourceAddressChannelHandler.ATTR_LOCAL_ADDRESS, + SourceAddressChannelHandler.ATTR_LOCAL_INET_ADDR, + SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS, + SourceAddressChannelHandler.ATTR_REMOTE_ADDR, + SourceAddressChannelHandler.ATTR_SOURCE_INET_ADDR, + SourceAddressChannelHandler.ATTR_SERVER_LOCAL_ADDRESS, + SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT, + SourceAddressChannelHandler.ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS, + Http2OrHttpHandler.PROTOCOL_NAME, + SslHandshakeInfoHandler.ATTR_SSL_INFO, + HAProxyMessageChannelHandler.ATTR_HAPROXY_MESSAGE, + HAProxyMessageChannelHandler.ATTR_HAPROXY_VERSION, + HAProxyMessageChannelHandler.ATTR_HAPROXY_CUSTOM_TLVS, + BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG, + Server.CONN_DIMENSIONS); + private static final Http2StreamHeaderCleaner http2StreamHeaderCleaner = new Http2StreamHeaderCleaner(); private static final Http2ResetFrameHandler http2ResetFrameHandler = new Http2ResetFrameHandler(); private static final Http2StreamErrorHandler http2StreamErrorHandler = new Http2StreamErrorHandler(); @@ -90,29 +110,12 @@ protected void addHttp2MetricsHandlers(ChannelPipeline pipeline) { } protected void copyAttrsFromParentChannel(Channel parent, Channel child) { - AttributeKey[] attributesToCopy = { - SourceAddressChannelHandler.ATTR_LOCAL_ADDRESS, - SourceAddressChannelHandler.ATTR_LOCAL_INET_ADDR, - SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS, - SourceAddressChannelHandler.ATTR_REMOTE_ADDR, - SourceAddressChannelHandler.ATTR_SOURCE_INET_ADDR, - SourceAddressChannelHandler.ATTR_SERVER_LOCAL_ADDRESS, - SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT, - SourceAddressChannelHandler.ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS, - Http2OrHttpHandler.PROTOCOL_NAME, - SslHandshakeInfoHandler.ATTR_SSL_INFO, - HAProxyMessageChannelHandler.ATTR_HAPROXY_MESSAGE, - HAProxyMessageChannelHandler.ATTR_HAPROXY_VERSION, - HAProxyMessageChannelHandler.ATTR_HAPROXY_CUSTOM_TLVS, - BaseZuulChannelInitializer.ATTR_CHANNEL_CONFIG - }; - - for (AttributeKey key : attributesToCopy) { - copyAttrFromParentChannel(parent, child, key); + for (AttributeKey<?> key : ATTRIBUTES_TO_COPY) { + copyAttributesFromParentChannel(parent, child, key); } } - protected void copyAttrFromParentChannel(Channel parent, Channel child, AttributeKey key) { + protected <T> void copyAttributesFromParentChannel(Channel parent, Channel child, AttributeKey<T> key) { child.attr(key).set(parent.attr(key).get()); } }