@@ -360,13 +360,13 @@ public Future<Void> writeCustomFrame(int type, int flags, Buffer payload) {
360360 synchronized (this ) {
361361 checkEnded ();
362362 }
363- return stream .writeFrame (type , flags , ((BufferInternal )payload ).getByteBuf ());
363+ return stream .writeFrame (type , flags , ((BufferInternal ) payload ).getByteBuf ());
364364 }
365365
366366 private void handleDrained (Void v ) {
367367 Handler <Void > handler ;
368368 synchronized (this ) {
369- handler = drainHandler ;
369+ handler = drainHandler ;
370370 if (handler == null || endFuture .isComplete ()) {
371371 return ;
372372 }
@@ -381,7 +381,7 @@ private void handleNextRequest(HttpClientRequest next, Promise<HttpClientRespons
381381 next .pushHandler (pushHandler ());
382382 next .setFollowRedirects (true );
383383 next .setMaxRedirects (maxRedirects );
384- ((HttpClientRequestImpl )next ).numberOfRedirections = numberOfRedirections + 1 ;
384+ ((HttpClientRequestImpl ) next ).numberOfRedirections = numberOfRedirections + 1 ;
385385 endFuture .onComplete (ar -> {
386386 if (ar .succeeded ()) {
387387 if (timeoutMs > 0 ) {
@@ -457,7 +457,7 @@ public Future<Void> end(String chunk, String enc) {
457457
458458 @ Override
459459 public Future <Void > end (Buffer chunk ) {
460- return write (((BufferInternal )chunk ).getByteBuf (), true );
460+ return write (((BufferInternal ) chunk ).getByteBuf (), true );
461461 }
462462
463463 @ Override
@@ -467,7 +467,7 @@ public Future<Void> end() {
467467
468468 @ Override
469469 public Future <Void > write (Buffer chunk ) {
470- ByteBuf buf = ((BufferInternal )chunk ).getByteBuf ();
470+ ByteBuf buf = ((BufferInternal ) chunk ).getByteBuf ();
471471 return write (buf , false );
472472 }
473473
@@ -482,16 +482,22 @@ public Future<Void> write(String chunk, String enc) {
482482 return write (BufferInternal .buffer (chunk , enc ).getByteBuf (), false );
483483 }
484484
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+ }
486492 return !chunked && (headers == null || !headers .contains (CONTENT_LENGTH )) && !isConnect ;
487493 }
488494
489495 private Future <Void > write (ByteBuf buff , boolean end ) {
490496 if (end ) {
491- if (buff != null && requiresContentLength ()) {
497+ if (buff != null && requiresContentLength (true )) {
492498 headers ().set (CONTENT_LENGTH , HttpUtils .positiveLongToString (buff .readableBytes ()));
493499 }
494- } else if (requiresContentLength ()) {
500+ } else if (requiresContentLength (false )) {
495501 throw new IllegalStateException ("You must set the Content-Length header to be the total size of the message "
496502 + "body BEFORE sending any data if you are not using HTTP chunked encoding." );
497503 }
0 commit comments