Skip to content

Commit

Permalink
Netty connector maxHeaderSize
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <[email protected]>
  • Loading branch information
senivam committed May 20, 2024
1 parent 14c5c43 commit 366ce79
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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";
}
}
Expand All @@ -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
Expand All @@ -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();
}
}

0 comments on commit 366ce79

Please sign in to comment.