Browse Source

Allow usage of GET with body in java11 Module (#1819)

pull/1823/head
f-cramer 2 years ago committed by GitHub
parent
commit
950935d593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      java11/src/main/java/feign/http2client/Http2Client.java
  2. 26
      java11/src/test/java/feign/http2client/test/Http2ClientTest.java

15
java11/src/main/java/feign/http2client/Http2Client.java

@ -190,20 +190,7 @@ public class Http2Client implements Client, AsyncClient<Object> { @@ -190,20 +190,7 @@ public class Http2Client implements Client, AsyncClient<Object> {
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);
}
/**

26
java11/src/test/java/feign/http2client/test/Http2ClientTest.java

@ -44,6 +44,14 @@ public class Http2ClientTest extends AbstractClientTest { @@ -44,6 +44,14 @@ public class Http2ClientTest extends AbstractClientTest {
@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
@ -115,6 +123,24 @@ public class Http2ClientTest extends AbstractClientTest { @@ -115,6 +123,24 @@ public class Http2ClientTest extends AbstractClientTest {
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());

Loading…
Cancel
Save