Skip to content

Commit

Permalink
Ensure body is sent when DELETE and Transfer-Encoding (#3481)
Browse files Browse the repository at this point in the history
According to the spec https://www.rfc-editor.org/rfc/rfc9110.html#name-delete

```
A client SHOULD NOT generate content in a DELETE request unless it is made
directly to an origin server that has previously indicated, in or out of band, that
such a request has a purpose and will be adequately supported.
```

When a user sends DELETE with content this means there is an indication that
the server supports this type of requests.
  • Loading branch information
violetagg authored Oct 24, 2024
1 parent 4cc2555 commit 4c835a3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ Publisher<Void> requestWithBody(HttpClientOperations ch) {

if (!Objects.equals(method, HttpMethod.GET) &&
!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 @@ -98,6 +98,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -3445,4 +3446,27 @@ void testIssue3416() {
.expectComplete()
.verify(Duration.ofSeconds(5));
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
void testDeleteMethod(boolean chunked) {
disposableServer =
createServer()
.handle((req, res) -> res.send(req.receive().retain()))
.bindNow();

Publisher<ByteBuf> body = chunked ?
ByteBufFlux.fromString(Flux.just("d", "e", "l", "e", "t", "e")) :
ByteBufMono.fromString(Mono.just("delete"));

createClient(disposableServer.port())
.delete()
.uri("/")
.send(body)
.responseSingle((res, bytes) -> bytes.asString())
.as(StepVerifier::create)
.expectNext("delete")
.expectComplete()
.verify(Duration.ofSeconds(5));
}
}

0 comments on commit 4c835a3

Please sign in to comment.