Skip to content

Commit 9caeff8

Browse files
pnepywodaAdrian Cole
authored andcommitted
support PUT with empty body parameter
follow-up commit to OpenFeign#271
1 parent 9f3424e commit 9caeff8

5 files changed

Lines changed: 49 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### Version 8.15
2+
* Supports PUT without a body parameter
3+
14
### Version 8.14
25
* Add support for RxJava Observable and Single return types via the `HystrixFeign` builder.
36
* Adds fallback implementation configuration to the `HystrixFeign` builder

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,24 @@ protected void log(String configKey, String format, Object... args) {
184184
}
185185

186186
@Test
187-
public void noResponseBody() {
187+
public void noResponseBodyForPost() {
188188
server.enqueue(new MockResponse());
189189

190190
TestInterface api = Feign.builder()
191191
.target(TestInterface.class, "http://localhost:" + server.getPort());
192192

193193
api.noPostBody();
194194
}
195+
196+
@Test
197+
public void noResponseBodyForPut() {
198+
server.enqueue(new MockResponse());
199+
200+
TestInterface api = Feign.builder()
201+
.target(TestInterface.class, "http://localhost:" + server.getPort());
202+
203+
api.noPutBody();
204+
}
195205

196206
interface TestInterface {
197207

@@ -209,5 +219,8 @@ interface TestInterface {
209219

210220
@RequestLine("POST")
211221
String noPostBody();
222+
223+
@RequestLine("PUT")
224+
String noPutBody();
212225
}
213226
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected void log(String configKey, String format, Object... args) {
136136
}
137137

138138
@Test
139-
public void noResponseBody() {
139+
public void noResponseBodyForPost() {
140140
server.enqueue(new MockResponse());
141141

142142
TestInterface api = Feign.builder()
@@ -145,6 +145,17 @@ public void noResponseBody() {
145145

146146
api.noPostBody();
147147
}
148+
149+
@Test
150+
public void noResponseBodyForPut() {
151+
server.enqueue(new MockResponse());
152+
153+
TestInterface api = Feign.builder()
154+
.client(new ApacheHttpClient())
155+
.target(TestInterface.class, "http://localhost:" + server.getPort());
156+
157+
api.noPutBody();
158+
}
148159
@Test
149160
public void postWithSpacesInPath() throws IOException, InterruptedException {
150161
server.enqueue(new MockResponse().setBody("foo"));
@@ -176,6 +187,9 @@ interface TestInterface {
176187

177188
@RequestLine("POST")
178189
String noPostBody();
190+
191+
@RequestLine("PUT")
192+
String noPutBody();
179193

180194
@RequestLine("POST /path/{to}/resource")
181195
@Headers("Accept: text/plain")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ static Request toOkHttpRequest(feign.Request input) {
7979
}
8080

8181
byte[] inputBody = input.body();
82-
if ("POST".equals(input.method()) && inputBody == null) {
82+
boolean isMethodWithBody = "POST".equals(input.method()) || "PUT".equals(input.method());
83+
if (isMethodWithBody && inputBody == null) {
8384
// write an empty BODY to conform with okhttp 2.4.0+
8485
// http://johnfeng.github.io/blog/2015/06/30/okhttp-updates-post-wouldnt-be-allowed-to-have-null-body/
8586
inputBody = new byte[0];

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected void log(String configKey, String format, Object... args) {
135135
}
136136

137137
@Test
138-
public void noResponseBody() {
138+
public void noResponseBodyForPost() {
139139
server.enqueue(new MockResponse());
140140

141141
TestInterface api = Feign.builder()
@@ -144,6 +144,17 @@ public void noResponseBody() {
144144

145145
api.noPostBody();
146146
}
147+
148+
@Test
149+
public void noResponseBodyForPut() {
150+
server.enqueue(new MockResponse());
151+
152+
TestInterface api = Feign.builder()
153+
.client(new OkHttpClient())
154+
.target(TestInterface.class, "http://localhost:" + server.getPort());
155+
156+
api.noPutBody();
157+
}
147158

148159
interface TestInterface {
149160

@@ -161,5 +172,8 @@ interface TestInterface {
161172

162173
@RequestLine("POST")
163174
String noPostBody();
175+
176+
@RequestLine("PUT")
177+
String noPutBody();
164178
}
165179
}

0 commit comments

Comments
 (0)