Skip to content

Commit

Permalink
Do not add Transfer-Encoding for DELETE with no body (#3549)
Browse files Browse the repository at this point in the history
This is a regression caused by #3481

Fixes #3548
  • Loading branch information
violetagg authored Dec 17, 2024
1 parent dfc9de9 commit 9288524
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ Publisher<Void> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ public NettyOutbound send(Publisher<? extends ByteBuf> 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)
Expand Down Expand Up @@ -480,7 +482,7 @@ public NettyOutbound send(Publisher<? extends ByteBuf> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3550,24 +3550,26 @@ 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<ByteBuf> body = chunked ?
Publisher<ByteBuf> 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()
.uri("/")
.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));
}
Expand Down

0 comments on commit 9288524

Please sign in to comment.