Skip to content

Commit 889992c

Browse files
author
David Golombek
committed
Add config for allowDuplicateContentLengths
Allow users to configure HttpClientCodec's parseHttpAfterConnectRequest and allowDuplicateContentLengths flags. Fixes AsyncHttpClient#1889
1 parent 4dee060 commit 889992c

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

client/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java

+4
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ public interface AsyncHttpClientConfig {
290290

291291
int getHttpClientCodecInitialBufferSize();
292292

293+
boolean getHttpClientParseHttpAfterConnectRequest();
294+
295+
boolean getHttpClientAllowDuplicateContentLengths();
296+
293297
boolean isDisableZeroCopy();
294298

295299
int getHandshakeTimeout();

client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClientConfig.java

+33
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHashedWheelTimerSize;
6767
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHashedWheelTimerTickDuration;
6868
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttpClientCodecInitialBufferSize;
69+
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttpClientParseHttpAfterConnectRequest;
70+
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttpClientAllowDuplicateContentLengths;
6971
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttpClientCodecMaxChunkSize;
7072
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttpClientCodecMaxHeaderSize;
7173
import static org.asynchttpclient.config.AsyncHttpClientConfigDefaults.defaultHttpClientCodecMaxInitialLineLength;
@@ -181,6 +183,8 @@ public class DefaultAsyncHttpClientConfig implements AsyncHttpClientConfig {
181183
private final int httpClientCodecMaxHeaderSize;
182184
private final int httpClientCodecMaxChunkSize;
183185
private final int httpClientCodecInitialBufferSize;
186+
private final boolean httpClientParseHttpAfterConnectRequest;
187+
private final boolean httpClientAllowDuplicateContentLengths;
184188
private final int chunkedFileChunkSize;
185189
private final Map<ChannelOption<Object>, Object> channelOptions;
186190
private final @Nullable EventLoopGroup eventLoopGroup;
@@ -275,6 +279,8 @@ private DefaultAsyncHttpClientConfig(// http
275279
int httpClientCodecMaxHeaderSize,
276280
int httpClientCodecMaxChunkSize,
277281
int httpClientCodecInitialBufferSize,
282+
boolean httpClientParseHttpAfterConnectRequest,
283+
boolean httpClientAllowDuplicateContentLengths,
278284
int chunkedFileChunkSize,
279285
int webSocketMaxBufferSize,
280286
int webSocketMaxFrameSize,
@@ -369,6 +375,8 @@ private DefaultAsyncHttpClientConfig(// http
369375
this.httpClientCodecMaxHeaderSize = httpClientCodecMaxHeaderSize;
370376
this.httpClientCodecMaxChunkSize = httpClientCodecMaxChunkSize;
371377
this.httpClientCodecInitialBufferSize = httpClientCodecInitialBufferSize;
378+
this.httpClientParseHttpAfterConnectRequest = httpClientParseHttpAfterConnectRequest;
379+
this.httpClientAllowDuplicateContentLengths = httpClientAllowDuplicateContentLengths;
372380
this.chunkedFileChunkSize = chunkedFileChunkSize;
373381
this.channelOptions = channelOptions;
374382
this.eventLoopGroup = eventLoopGroup;
@@ -704,6 +712,17 @@ public int getHttpClientCodecInitialBufferSize() {
704712
return httpClientCodecInitialBufferSize;
705713
}
706714

715+
@Override
716+
public boolean getHttpClientParseHttpAfterConnectRequest() {
717+
return httpClientParseHttpAfterConnectRequest;
718+
}
719+
720+
@Override
721+
public boolean getHttpClientAllowDuplicateContentLengths() {
722+
return httpClientAllowDuplicateContentLengths;
723+
}
724+
725+
707726
@Override
708727
public int getChunkedFileChunkSize() {
709728
return chunkedFileChunkSize;
@@ -857,6 +876,8 @@ public static class Builder {
857876
private int httpClientCodecMaxHeaderSize = defaultHttpClientCodecMaxHeaderSize();
858877
private int httpClientCodecMaxChunkSize = defaultHttpClientCodecMaxChunkSize();
859878
private int httpClientCodecInitialBufferSize = defaultHttpClientCodecInitialBufferSize();
879+
private boolean httpClientParseHttpAfterConnectRequest = defaultHttpClientParseHttpAfterConnectRequest();
880+
private boolean httpClientAllowDuplicateContentLengths = defaultHttpClientAllowDuplicateContentLengths();
860881
private int chunkedFileChunkSize = defaultChunkedFileChunkSize();
861882
private boolean useNativeTransport = defaultUseNativeTransport();
862883
private boolean useOnlyEpollNativeTransport = defaultUseOnlyEpollNativeTransport();
@@ -1329,6 +1350,16 @@ public Builder setHttpClientCodecInitialBufferSize(int httpClientCodecInitialBuf
13291350
return this;
13301351
}
13311352

1353+
public Builder setHttpClientParseHttpAfterConnectRequest(boolean httpClientParseHttpAfterConnectRequest) {
1354+
this.httpClientParseHttpAfterConnectRequest = httpClientParseHttpAfterConnectRequest;
1355+
return this;
1356+
}
1357+
1358+
public Builder setHttpClientAllowDuplicateContentLengths(boolean httpClientAllowDuplicateContentLengths) {
1359+
this.httpClientAllowDuplicateContentLengths = httpClientAllowDuplicateContentLengths;
1360+
return this;
1361+
}
1362+
13321363
public Builder setChunkedFileChunkSize(int chunkedFileChunkSize) {
13331364
this.chunkedFileChunkSize = chunkedFileChunkSize;
13341365
return this;
@@ -1477,6 +1508,8 @@ public DefaultAsyncHttpClientConfig build() {
14771508
httpClientCodecMaxHeaderSize,
14781509
httpClientCodecMaxChunkSize,
14791510
httpClientCodecInitialBufferSize,
1511+
httpClientParseHttpAfterConnectRequest,
1512+
httpClientAllowDuplicateContentLengths,
14801513
chunkedFileChunkSize,
14811514
webSocketMaxBufferSize,
14821515
webSocketMaxFrameSize,

client/src/main/java/org/asynchttpclient/config/AsyncHttpClientConfigDefaults.java

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public final class AsyncHttpClientConfigDefaults {
6969
public static final String HTTP_CLIENT_CODEC_MAX_HEADER_SIZE_CONFIG = "httpClientCodecMaxHeaderSize";
7070
public static final String HTTP_CLIENT_CODEC_MAX_CHUNK_SIZE_CONFIG = "httpClientCodecMaxChunkSize";
7171
public static final String HTTP_CLIENT_CODEC_INITIAL_BUFFER_SIZE_CONFIG = "httpClientCodecInitialBufferSize";
72+
public static final String HTTP_CLIENT_CODEC_PARSE_HTTP_AFTER_CONNECT_REQUEST = "httpClientCodecParseHttpAfterConnectRequest";
73+
public static final String HTTP_CLIENT_CODEC_ALLOW_DUPLICATE_CONTENT_LENGTHS = "httpClientCodecAllowDuplicateContentLengths";
7274
public static final String DISABLE_ZERO_COPY_CONFIG = "disableZeroCopy";
7375
public static final String HANDSHAKE_TIMEOUT_CONFIG = "handshakeTimeout";
7476
public static final String CHUNKED_FILE_CHUNK_SIZE_CONFIG = "chunkedFileChunkSize";
@@ -271,6 +273,14 @@ public static int defaultHttpClientCodecInitialBufferSize() {
271273
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getInt(ASYNC_CLIENT_CONFIG_ROOT + HTTP_CLIENT_CODEC_INITIAL_BUFFER_SIZE_CONFIG);
272274
}
273275

276+
public static boolean defaultHttpClientParseHttpAfterConnectRequest() {
277+
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + HTTP_CLIENT_CODEC_PARSE_HTTP_AFTER_CONNECT_REQUEST);
278+
}
279+
280+
public static boolean defaultHttpClientAllowDuplicateContentLengths() {
281+
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + HTTP_CLIENT_CODEC_ALLOW_DUPLICATE_CONTENT_LENGTHS);
282+
}
283+
274284
public static boolean defaultDisableZeroCopy() {
275285
return AsyncHttpClientConfigHelper.getAsyncHttpClientConfig().getBoolean(ASYNC_CLIENT_CONFIG_ROOT + DISABLE_ZERO_COPY_CONFIG);
276286
}

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ private HttpClientCodec newHttpClientCodec() {
366366
config.getHttpClientCodecMaxChunkSize(),
367367
false,
368368
config.isValidateResponseHeaders(),
369-
config.getHttpClientCodecInitialBufferSize());
369+
config.getHttpClientCodecInitialBufferSize(),
370+
config.getHttpClientParseHttpAfterConnectRequest(),
371+
config.getHttpClientAllowDuplicateContentLengths());
370372
}
371373

372374
private SslHandler createSslHandler(String peerHost, int peerPort) {

client/src/main/resources/org/asynchttpclient/config/ahc-default.properties

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ org.asynchttpclient.httpClientCodecMaxInitialLineLength=4096
4141
org.asynchttpclient.httpClientCodecMaxHeaderSize=8192
4242
org.asynchttpclient.httpClientCodecMaxChunkSize=8192
4343
org.asynchttpclient.httpClientCodecInitialBufferSize=128
44+
org.asynchttpclient.httpClientCodecParseHttpAfterConnectRequest=false
45+
org.asynchttpclient.httpClientCodecAllowDuplicateContentLengths=false
4446
org.asynchttpclient.disableZeroCopy=false
4547
org.asynchttpclient.handshakeTimeout=10000
4648
org.asynchttpclient.chunkedFileChunkSize=8192

0 commit comments

Comments
 (0)