Skip to content

Commit

Permalink
Allow usage of GET with body in java11 Module (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-cramer committed Nov 2, 2022
1 parent b57ab51 commit 950935d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
15 changes: 1 addition & 14 deletions java11/src/main/java/feign/http2client/Http2Client.java
Expand Up @@ -190,20 +190,7 @@ private Builder newRequestBuilder(Request request, Options options) throws URISy
requestBuilder.headers(asString(headers));
}

switch (request.httpMethod()) {
case GET:
return requestBuilder.GET();
case POST:
return requestBuilder.POST(body);
case PUT:
return requestBuilder.PUT(body);
case DELETE:
return requestBuilder.DELETE();
default:
// fall back scenario, http implementations may restrict some methods
return requestBuilder.method(request.httpMethod().toString(), body);
}

return requestBuilder.method(request.httpMethod().toString(), body);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions java11/src/test/java/feign/http2client/test/Http2ClientTest.java
Expand Up @@ -44,6 +44,14 @@ public interface TestInterface {
@RequestLine("POST /timeout")
@Headers({"Accept: text/plain"})
String timeout();

@RequestLine("GET /anything")
@Body("some request body")
String getWithBody();

@RequestLine("DELETE /anything")
@Body("some request body")
String deleteWithBody();
}

@Override
Expand Down Expand Up @@ -115,6 +123,24 @@ public void timeoutTest() {
api.timeout();
}

@Test
public void testGetWithRequestBody() {
final TestInterface api =
newBuilder().target(TestInterface.class, "https://nghttp2.org/httpbin/");
String result = api.getWithBody();
Assertions.assertThat(result)
.contains("\"data\": \"some request body\"");
}

@Test
public void testDeleteWithRequestBody() {
final TestInterface api =
newBuilder().target(TestInterface.class, "https://nghttp2.org/httpbin/");
String result = api.deleteWithBody();
Assertions.assertThat(result)
.contains("\"data\": \"some request body\"");
}

@Override
public Feign.Builder newBuilder() {
return Feign.builder().client(new Http2Client());
Expand Down

0 comments on commit 950935d

Please sign in to comment.