diff --git a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyClientProperties.java b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyClientProperties.java index 9c79d1281d6..e9a1ba5c091 100644 --- a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyClientProperties.java +++ b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyClientProperties.java @@ -129,4 +129,56 @@ public class NettyClientProperties { public static final Integer DEFAULT_EXPECT_100_CONTINUE_TIMEOUT_VALUE = 500; + + /** + * Parameter which allows extending of the header size for the Netty connector + * + * @since 2.44 + */ + public static final String + MAX_HEADER_SIZE = "jersey.config.client.netty.maxHeaderSize"; + + /** + * Default header size for Netty Connector. + * Taken from {@link io.netty.handler.codec.http.HttpClientCodec#HttpClientCodec(int, int, int)} + * + * @since 2.44 + */ + public static final Integer + DEFAULT_HEADER_SIZE = 8192; + + /** + * Parameter which allows extending of the initial line length for the Netty connector + * + * @since 2.44 + */ + public static final String + MAX_INITIAL_LINE_LENGTH = "jersey.config.client.netty.maxInitialLineLength"; + + /** + * Default initial line length for Netty Connector. + * Taken from {@link io.netty.handler.codec.http.HttpClientCodec#HttpClientCodec(int, int, int)} + * + * @since 2.44 + */ + public static final Integer + DEFAULT_INITIAL_LINE_LENGTH = 4096; + + /** + * Parameter which allows extending of the chunk size for the Netty connector + * + * @since 2.44 + */ + public static final String + MAX_CHUNK_SIZE = "jersey.config.client.netty.maxChunkSize"; + + /** + * Default chunk size for Netty Connector. + * Taken from {@link io.netty.handler.codec.http.HttpClientCodec#HttpClientCodec(int, int, int)} + * + * @since 2.44 + */ + public static final Integer + DEFAULT_CHUNK_SIZE = 8192; + } diff --git a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java index 1a548dcb263..9ccab771c4f 100644 --- a/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java +++ b/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java @@ -302,7 +302,20 @@ protected void initChannel(SocketChannel ch) throws Exception { p.addLast(sslHandler); } - p.addLast(new HttpClientCodec()); + final Integer maxHeaderSize = ClientProperties.getValue(config.getProperties(), + NettyClientProperties.MAX_HEADER_SIZE, + NettyClientProperties.DEFAULT_HEADER_SIZE); + final Integer maxChunkSize = ClientProperties.getValue(config.getProperties(), + NettyClientProperties.MAX_CHUNK_SIZE, + NettyClientProperties.DEFAULT_CHUNK_SIZE); + final Integer maxInitialLineLength = ClientProperties.getValue(config.getProperties(), + NettyClientProperties.MAX_INITIAL_LINE_LENGTH, + NettyClientProperties.DEFAULT_INITIAL_LINE_LENGTH); + + System.out.println("maxHeaderSize: " + maxHeaderSize); + System.out.println("maxChunkSize: " + maxChunkSize); + System.out.println("maxInitialLineLength: " + maxInitialLineLength); + p.addLast(new HttpClientCodec(maxInitialLineLength, maxHeaderSize, maxChunkSize)); p.addLast(new ChunkedWriteHandler()); p.addLast(new HttpContentDecompressor()); } diff --git a/connectors/netty-connector/src/test/java/org/glassfish/jersey/netty/connector/HttpHeadersTest.java b/connectors/netty-connector/src/test/java/org/glassfish/jersey/netty/connector/HttpHeadersTest.java index c3a9c1bfd07..37e1e61589b 100644 --- a/connectors/netty-connector/src/test/java/org/glassfish/jersey/netty/connector/HttpHeadersTest.java +++ b/connectors/netty-connector/src/test/java/org/glassfish/jersey/netty/connector/HttpHeadersTest.java @@ -36,6 +36,17 @@ * @author Stepan Kopriva */ public class HttpHeadersTest extends JerseyTest { + + private static final String hugeHeader = "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyz"; @Path("/test") public static class HttpMethodResource { @POST @@ -52,8 +63,12 @@ public String post( public String get( @HeaderParam("Transfer-Encoding") String transferEncoding, @HeaderParam("X-CLIENT") String xClient, - @HeaderParam("X-WRITER") String xWriter) { + @HeaderParam("X-WRITER") String xWriter, + @HeaderParam("X-HUGE-HEADER") String hugeHeader) { assertEquals("client", xClient); + if (hugeHeader != null) { + System.out.println(hugeHeader.length()); + } return "GET"; } } @@ -65,7 +80,9 @@ protected Application configure() { @Override protected void configureClient(ClientConfig config) { - config.connectorProvider(new NettyConnectorProvider()); + config.connectorProvider(new NettyConnectorProvider()) + .property(NettyClientProperties.MAX_HEADER_SIZE, 77750) + .property(NettyClientProperties.MAX_CHUNK_SIZE, 77750); } @Test @@ -85,4 +102,26 @@ public void testGet() { assertTrue(response.hasEntity()); response.close(); } + + @Test + public void testHeaderSize() { + final StringBuffer veryHugeHeader = new StringBuffer(); + ; + for (int i = 1; i < 33; i++) { + veryHugeHeader.append(hugeHeader); + } + System.out.println(veryHugeHeader.length()); + Response response = //getClient() + //.property(NettyClientProperties.MAX_HEADER_SIZE, + // NettyClientProperties.DEFAULT_HEADER_SIZE) + target("test") + .request() + .header("X-CLIENT", "client") + .header("X-HUGE-HEADER", veryHugeHeader.toString()) + .post(null); + System.out.println(response.getHeaders()); + assertEquals(200, response.getStatus()); + assertTrue(response.hasEntity()); + response.close(); + } }