Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid converting empty GET body to POST
Signed-off-by: hutiefang <[email protected]>
  • Loading branch information
hutiefang committed Jul 1, 2026
commit 9ec9802e41a571ffa755c67b16fc4933af6f11f8
2 changes: 1 addition & 1 deletion core/src/main/java/feign/DefaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ else if (field.equals(ACCEPT_ENCODING)) {

byte[] body = request.body();

if (body != null) {
if (body != null && (body.length > 0 || request.httpMethod() != Request.HttpMethod.GET)) {
/*
* Ignore disableRequestBuffering flag if the empty body was set, to ensure that internal
* retry logic applies to such requests.
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/java/feign/client/DefaultClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import feign.DefaultClient;
import feign.Feign;
import feign.Feign.Builder;
import feign.Request;
import feign.Request.HttpMethod;
import feign.RetryableException;
import feign.assertj.MockWebServerAssertions;
import java.io.IOException;
Expand Down Expand Up @@ -101,6 +103,22 @@ public void noRequestBodyForPostWithAllowRestrictedHeaders() throws Exception {
.hasHeaders(entry("Content-Length", Collections.singletonList("0")));
}

@Test
void emptyBodyDoesNotConvertGetToPost() throws Exception {
server.enqueue(new MockResponse().setBody("foo"));
Request request =
Request.create(
HttpMethod.GET,
"http://localhost:" + server.getPort() + "/",
Collections.emptyMap(),
new byte[0],
null);

new DefaultClient(null, null).execute(request, new Request.Options());

MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("GET");
}

@Test
@Override
public void noResponseBodyForPut() throws Exception {
Expand Down