From 9288524bc602154124f8b63ae3ee6feb9c0a8058 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Tue, 17 Dec 2024 21:07:07 +0200 Subject: [PATCH] Do not add Transfer-Encoding for DELETE with no body (#3549) This is a regression caused by #3481 Fixes #3548 --- .../netty/http/client/HttpClientConnect.java | 5 +++-- .../netty/http/client/HttpClientOperations.java | 6 ++++-- .../reactor/netty/http/client/HttpClientTest.java | 14 ++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java index 8453728a0..e078e6c4e 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConnect.java @@ -576,8 +576,9 @@ Publisher requestWithBody(HttpClientOperations ch) { ch.followRedirectPredicate(followRedirectPredicate); if (!Objects.equals(method, HttpMethod.GET) && - !Objects.equals(method, HttpMethod.HEAD) && - !headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { + !Objects.equals(method, HttpMethod.HEAD) && + !Objects.equals(method, HttpMethod.DELETE) && + !headers.contains(HttpHeaderNames.CONTENT_LENGTH)) { ch.chunkedTransfer(true); } diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientOperations.java b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientOperations.java index a2f527e06..9749dc456 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientOperations.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientOperations.java @@ -445,7 +445,9 @@ public NettyOutbound send(Publisher source) { if (source instanceof Mono) { return super.send(source); } - if (Objects.equals(method(), HttpMethod.GET) || Objects.equals(method(), HttpMethod.HEAD)) { + if (Objects.equals(method(), HttpMethod.GET) || + Objects.equals(method(), HttpMethod.HEAD) || + Objects.equals(method(), HttpMethod.DELETE)) { ByteBufAllocator alloc = channel().alloc(); return new PostHeadersNettyOutbound(Flux.from(source) @@ -480,7 +482,7 @@ public NettyOutbound send(Publisher source) { } for (ByteBuf bb : list) { if (log.isDebugEnabled()) { - log.debug(format(channel(), "Ignoring accumulated bytebuf on http GET {}"), bb); + log.debug(format(channel(), "Ignoring accumulated bytebuf on http {} {}"), method(), bb); } bb.release(); } diff --git a/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java b/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java index 5ca837920..59c46ac69 100644 --- a/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java +++ b/reactor-netty-http/src/test/java/reactor/netty/http/client/HttpClientTest.java @@ -3550,16 +3550,18 @@ void testIssue3416() { } @ParameterizedTest - @ValueSource(booleans = {true, false}) - void testDeleteMethod(boolean chunked) { + @ValueSource(strings = {"mono", "flux", "empty"}) + void testDeleteMethod(String requestBodyType) { disposableServer = createServer() - .handle((req, res) -> res.send(req.receive().retain())) + .handle((req, res) -> res.sendString( + Flux.concat(req.receive().retain().aggregate().asString().defaultIfEmpty("empty"), + Mono.just(" " + req.requestHeaders().get(HttpHeaderNames.CONTENT_LENGTH))))) .bindNow(); - Publisher body = chunked ? + Publisher body = "flux".equals(requestBodyType) ? ByteBufFlux.fromString(Flux.just("d", "e", "l", "e", "t", "e")) : - ByteBufMono.fromString(Mono.just("delete")); + "mono".equals(requestBodyType) ? ByteBufMono.fromString(Mono.just("delete")) : Mono.empty(); createClient(disposableServer.port()) .delete() @@ -3567,7 +3569,7 @@ void testDeleteMethod(boolean chunked) { .send(body) .responseSingle((res, bytes) -> bytes.asString()) .as(StepVerifier::create) - .expectNext("delete") + .expectNext("empty".equals(requestBodyType) ? "empty 0" : "delete 6") .expectComplete() .verify(Duration.ofSeconds(5)); }