@@ -151,6 +151,12 @@ public class NettyAsyncHttpProvider extends SimpleChannelUpstreamHandler impleme
151
151
private final AsyncHttpClientConfig config ;
152
152
private final AtomicBoolean isClose = new AtomicBoolean (false );
153
153
private final ClientSocketChannelFactory socketChannelFactory ;
154
+ private int httpClientCodecMaxInitialLineLength = 4096 ;
155
+ private int httpClientCodecMaxHeaderSize = 8192 ;
156
+ private int httpClientCodecMaxChunkSize = 8192 ;
157
+ private int httpsClientCodecMaxInitialLineLength = 4096 ;
158
+ private int httpsClientCodecMaxHeaderSize = 8192 ;
159
+ private int httpsClientCodecMaxChunkSize = 8192 ;
154
160
155
161
private final ChannelGroup openChannels = new
156
162
CleanupChannelGroup ("asyncHttpClient" ) {
@@ -238,6 +244,8 @@ void configureNetty() {
238
244
for (Entry <String , Object > entry : asyncHttpProviderConfig .propertiesSet ()) {
239
245
plainBootstrap .setOption (entry .getKey (), entry .getValue ());
240
246
}
247
+ configureHttpClientCodec ();
248
+ configureHttpsClientCodec ();
241
249
}
242
250
243
251
plainBootstrap .setPipelineFactory (new ChannelPipelineFactory () {
@@ -246,7 +254,7 @@ void configureNetty() {
246
254
public ChannelPipeline getPipeline () throws Exception {
247
255
ChannelPipeline pipeline = pipeline ();
248
256
249
- pipeline .addLast (HTTP_HANDLER , new HttpClientCodec ());
257
+ pipeline .addLast (HTTP_HANDLER , createHttpClientCodec ());
250
258
251
259
if (config .getRequestCompressionLevel () > 0 ) {
252
260
pipeline .addLast ("deflater" , new HttpContentCompressor (config .getRequestCompressionLevel ()));
@@ -284,6 +292,42 @@ public ChannelPipeline getPipeline() throws Exception {
284
292
});
285
293
}
286
294
295
+ protected void configureHttpClientCodec () {
296
+ httpClientCodecMaxInitialLineLength = asyncHttpProviderConfig .getProperty (
297
+ NettyAsyncHttpProviderConfig .HTTP_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH ,
298
+ Integer .class ,
299
+ httpClientCodecMaxInitialLineLength
300
+ );
301
+ httpClientCodecMaxHeaderSize = asyncHttpProviderConfig .getProperty (
302
+ NettyAsyncHttpProviderConfig .HTTP_CLIENT_CODEC_MAX_HEADER_SIZE ,
303
+ Integer .class ,
304
+ httpClientCodecMaxHeaderSize
305
+ );
306
+ httpClientCodecMaxChunkSize = asyncHttpProviderConfig .getProperty (
307
+ NettyAsyncHttpProviderConfig .HTTP_CLIENT_CODEC_MAX_CHUNK_SIZE ,
308
+ Integer .class ,
309
+ httpClientCodecMaxChunkSize
310
+ );
311
+ }
312
+
313
+ protected void configureHttpsClientCodec () {
314
+ httpsClientCodecMaxInitialLineLength = asyncHttpProviderConfig .getProperty (
315
+ NettyAsyncHttpProviderConfig .HTTPS_CLIENT_CODEC_MAX_INITIAL_LINE_LENGTH ,
316
+ Integer .class ,
317
+ httpsClientCodecMaxInitialLineLength
318
+ );
319
+ httpsClientCodecMaxHeaderSize = asyncHttpProviderConfig .getProperty (
320
+ NettyAsyncHttpProviderConfig .HTTPS_CLIENT_CODEC_MAX_HEADER_SIZE ,
321
+ Integer .class ,
322
+ httpsClientCodecMaxHeaderSize
323
+ );
324
+ httpsClientCodecMaxChunkSize = asyncHttpProviderConfig .getProperty (
325
+ NettyAsyncHttpProviderConfig .HTTPS_CLIENT_CODEC_MAX_CHUNK_SIZE ,
326
+ Integer .class ,
327
+ httpsClientCodecMaxChunkSize
328
+ );
329
+ }
330
+
287
331
void constructSSLPipeline (final NettyConnectListener <?> cl ) {
288
332
289
333
secureBootstrap .setPipelineFactory (new ChannelPipelineFactory () {
@@ -298,7 +342,7 @@ public ChannelPipeline getPipeline() throws Exception {
298
342
abort (cl .future (), ex );
299
343
}
300
344
301
- pipeline .addLast (HTTP_HANDLER , new HttpClientCodec ());
345
+ pipeline .addLast (HTTP_HANDLER , createHttpsClientCodec ());
302
346
303
347
if (config .isCompressionEnabled ()) {
304
348
pipeline .addLast ("inflater" , new HttpContentDecompressor ());
@@ -363,6 +407,14 @@ private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException
363
407
return sslEngine ;
364
408
}
365
409
410
+ private HttpClientCodec createHttpClientCodec () {
411
+ return new HttpClientCodec (httpClientCodecMaxInitialLineLength , httpClientCodecMaxHeaderSize , httpClientCodecMaxChunkSize );
412
+ }
413
+
414
+ private HttpClientCodec createHttpsClientCodec () {
415
+ return new HttpClientCodec (httpsClientCodecMaxInitialLineLength , httpsClientCodecMaxHeaderSize , httpsClientCodecMaxChunkSize );
416
+ }
417
+
366
418
private Channel verifyChannelPipeline (Channel channel , String scheme ) throws IOException , GeneralSecurityException {
367
419
368
420
if (channel .getPipeline ().get (SSL_HANDLER ) != null && HTTP .equalsIgnoreCase (scheme )) {
@@ -547,7 +599,6 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
547
599
ChannelBuffer buffer ) throws IOException {
548
600
549
601
String host = AsyncHttpProviderUtils .getHost (uri );
550
- boolean webSocket = isWebSocket (uri );
551
602
552
603
if (request .getVirtualHost () != null ) {
553
604
host = request .getVirtualHost ();
@@ -568,12 +619,11 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
568
619
}
569
620
nettyRequest = new DefaultHttpRequest (HttpVersion .HTTP_1_1 , m , path .toString ());
570
621
}
571
-
622
+ boolean webSocket = isWebSocket ( uri );
572
623
if (webSocket ) {
573
624
nettyRequest .addHeader (HttpHeaders .Names .UPGRADE , HttpHeaders .Values .WEBSOCKET );
574
625
nettyRequest .addHeader (HttpHeaders .Names .CONNECTION , HttpHeaders .Values .UPGRADE );
575
- nettyRequest .addHeader ("Origin" , "http://" + uri .getHost () + ":"
576
- + (uri .getPort () == -1 ? isSecure (uri .getScheme ()) ? 443 : 80 : uri .getPort ()));
626
+ nettyRequest .addHeader ("Origin" , "http://" + uri .getHost () + ":" + uri .getPort ());
577
627
nettyRequest .addHeader (WEBSOCKET_KEY , WebSocketUtil .getKey ());
578
628
nettyRequest .addHeader ("Sec-WebSocket-Version" , "13" );
579
629
}
@@ -2346,13 +2396,7 @@ public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
2346
2396
s = new ResponseStatus (future .getURI (), response , NettyAsyncHttpProvider .this );
2347
2397
final boolean statusReceived = h .onStatusReceived (s ) == STATE .UPGRADE ;
2348
2398
2349
- if (!statusReceived ) {
2350
- h .onClose (new NettyWebSocket (ctx .getChannel ()), 1002 , "Bad response status " + response .getStatus ().getCode ());
2351
- future .done (null );
2352
- return ;
2353
- }
2354
-
2355
- if (!validStatus || !validUpgrade || !validConnection ) {
2399
+ if (!validStatus || !validUpgrade || !validConnection || !statusReceived ) {
2356
2400
throw new IOException ("Invalid handshake response" );
2357
2401
}
2358
2402
@@ -2463,4 +2507,3 @@ private static boolean isSecure(URI uri) {
2463
2507
return isSecure (uri .getScheme ());
2464
2508
}
2465
2509
}
2466
-
0 commit comments