Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow usage of GET with body in java11 Module #1819

Merged
merged 1 commit into from Nov 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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