@@ -360,13 +360,13 @@ public Future<Void> writeCustomFrame(int type, int flags, Buffer payload) {
360
360
synchronized (this ) {
361
361
checkEnded ();
362
362
}
363
- return stream .writeFrame (type , flags , ((BufferInternal )payload ).getByteBuf ());
363
+ return stream .writeFrame (type , flags , ((BufferInternal ) payload ).getByteBuf ());
364
364
}
365
365
366
366
private void handleDrained (Void v ) {
367
367
Handler <Void > handler ;
368
368
synchronized (this ) {
369
- handler = drainHandler ;
369
+ handler = drainHandler ;
370
370
if (handler == null || endFuture .isComplete ()) {
371
371
return ;
372
372
}
@@ -381,7 +381,7 @@ private void handleNextRequest(HttpClientRequest next, Promise<HttpClientRespons
381
381
next .pushHandler (pushHandler ());
382
382
next .setFollowRedirects (true );
383
383
next .setMaxRedirects (maxRedirects );
384
- ((HttpClientRequestImpl )next ).numberOfRedirections = numberOfRedirections + 1 ;
384
+ ((HttpClientRequestImpl ) next ).numberOfRedirections = numberOfRedirections + 1 ;
385
385
endFuture .onComplete (ar -> {
386
386
if (ar .succeeded ()) {
387
387
if (timeoutMs > 0 ) {
@@ -457,7 +457,7 @@ public Future<Void> end(String chunk, String enc) {
457
457
458
458
@ Override
459
459
public Future <Void > end (Buffer chunk ) {
460
- return write (((BufferInternal )chunk ).getByteBuf (), true );
460
+ return write (((BufferInternal ) chunk ).getByteBuf (), true );
461
461
}
462
462
463
463
@ Override
@@ -467,7 +467,7 @@ public Future<Void> end() {
467
467
468
468
@ Override
469
469
public Future <Void > write (Buffer chunk ) {
470
- ByteBuf buf = ((BufferInternal )chunk ).getByteBuf ();
470
+ ByteBuf buf = ((BufferInternal ) chunk ).getByteBuf ();
471
471
return write (buf , false );
472
472
}
473
473
@@ -482,16 +482,22 @@ public Future<Void> write(String chunk, String enc) {
482
482
return write (BufferInternal .buffer (chunk , enc ).getByteBuf (), false );
483
483
}
484
484
485
- private boolean requiresContentLength () {
485
+ private boolean requiresContentLength (boolean writeHead ) {
486
+ if (writeHead ) {
487
+ return !chunked && (headers == null || !headers .contains (CONTENT_LENGTH )) && !isConnect ;
488
+ }
489
+ if (version () == HttpVersion .HTTP_2 ) {
490
+ return false ;
491
+ }
486
492
return !chunked && (headers == null || !headers .contains (CONTENT_LENGTH )) && !isConnect ;
487
493
}
488
494
489
495
private Future <Void > write (ByteBuf buff , boolean end ) {
490
496
if (end ) {
491
- if (buff != null && requiresContentLength ()) {
497
+ if (buff != null && requiresContentLength (true )) {
492
498
headers ().set (CONTENT_LENGTH , HttpUtils .positiveLongToString (buff .readableBytes ()));
493
499
}
494
- } else if (requiresContentLength ()) {
500
+ } else if (requiresContentLength (false )) {
495
501
throw new IllegalStateException ("You must set the Content-Length header to be the total size of the message "
496
502
+ "body BEFORE sending any data if you are not using HTTP chunked encoding." );
497
503
}
0 commit comments