Browse Source

support PUT with empty body parameter

follow-up commit to https://github.com/Netflix/feign/pull/271
pull/322/head
Paul Nepywoda 9 years ago
parent
commit
e17aaed40d
  1. 3
      CHANGELOG.md
  2. 15
      core/src/test/java/feign/client/DefaultClientTest.java
  3. 16
      httpclient/src/test/java/feign/httpclient/ApacheHttpClientTest.java
  4. 3
      okhttp/src/main/java/feign/okhttp/OkHttpClient.java
  5. 16
      okhttp/src/test/java/feign/okhttp/OkHttpClientTest.java

3
CHANGELOG.md

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
### Version 8.15
* Supports PUT without a body parameter
### Version 8.14
* Add support for RxJava Observable and Single return types via the `HystrixFeign` builder.
* Adds fallback implementation configuration to the `HystrixFeign` builder

15
core/src/test/java/feign/client/DefaultClientTest.java

@ -184,7 +184,7 @@ public class DefaultClientTest { @@ -184,7 +184,7 @@ public class DefaultClientTest {
}
@Test
public void noResponseBody() {
public void noResponseBodyForPost() {
server.enqueue(new MockResponse());
TestInterface api = Feign.builder()
@ -192,6 +192,16 @@ public class DefaultClientTest { @@ -192,6 +192,16 @@ public class DefaultClientTest {
api.noPostBody();
}
@Test
public void noResponseBodyForPut() {
server.enqueue(new MockResponse());
TestInterface api = Feign.builder()
.target(TestInterface.class, "http://localhost:" + server.getPort());
api.noPutBody();
}
interface TestInterface {
@ -209,5 +219,8 @@ public class DefaultClientTest { @@ -209,5 +219,8 @@ public class DefaultClientTest {
@RequestLine("POST")
String noPostBody();
@RequestLine("PUT")
String noPutBody();
}
}

16
httpclient/src/test/java/feign/httpclient/ApacheHttpClientTest.java

@ -153,7 +153,7 @@ public class ApacheHttpClientTest { @@ -153,7 +153,7 @@ public class ApacheHttpClientTest {
}
@Test
public void noResponseBody() {
public void noResponseBodyForPost() {
server.enqueue(new MockResponse());
TestInterface api = Feign.builder()
@ -162,6 +162,17 @@ public class ApacheHttpClientTest { @@ -162,6 +162,17 @@ public class ApacheHttpClientTest {
api.noPostBody();
}
@Test
public void noResponseBodyForPut() {
server.enqueue(new MockResponse());
TestInterface api = Feign.builder()
.client(new ApacheHttpClient())
.target(TestInterface.class, "http://localhost:" + server.getPort());
api.noPutBody();
}
@Test
public void postWithSpacesInPath() throws IOException, InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
@ -193,6 +204,9 @@ public class ApacheHttpClientTest { @@ -193,6 +204,9 @@ public class ApacheHttpClientTest {
@RequestLine("POST")
String noPostBody();
@RequestLine("PUT")
String noPutBody();
@RequestLine("POST /path/{to}/resource")
@Headers("Accept: text/plain")

3
okhttp/src/main/java/feign/okhttp/OkHttpClient.java

@ -79,7 +79,8 @@ public final class OkHttpClient implements Client { @@ -79,7 +79,8 @@ public final class OkHttpClient implements Client {
}
byte[] inputBody = input.body();
if ("POST".equals(input.method()) && inputBody == null) {
boolean isMethodWithBody = "POST".equals(input.method()) || "PUT".equals(input.method());
if (isMethodWithBody && inputBody == null) {
// write an empty BODY to conform with okhttp 2.4.0+
// http://johnfeng.github.io/blog/2015/06/30/okhttp-updates-post-wouldnt-be-allowed-to-have-null-body/
inputBody = new byte[0];

16
okhttp/src/test/java/feign/okhttp/OkHttpClientTest.java

@ -135,7 +135,7 @@ public class OkHttpClientTest { @@ -135,7 +135,7 @@ public class OkHttpClientTest {
}
@Test
public void noResponseBody() {
public void noResponseBodyForPost() {
server.enqueue(new MockResponse());
TestInterface api = Feign.builder()
@ -144,6 +144,17 @@ public class OkHttpClientTest { @@ -144,6 +144,17 @@ public class OkHttpClientTest {
api.noPostBody();
}
@Test
public void noResponseBodyForPut() {
server.enqueue(new MockResponse());
TestInterface api = Feign.builder()
.client(new OkHttpClient())
.target(TestInterface.class, "http://localhost:" + server.getPort());
api.noPutBody();
}
interface TestInterface {
@ -161,5 +172,8 @@ public class OkHttpClientTest { @@ -161,5 +172,8 @@ public class OkHttpClientTest {
@RequestLine("POST")
String noPostBody();
@RequestLine("PUT")
String noPutBody();
}
}

Loading…
Cancel
Save