update gateway mvc post, put, and patch request body not required.

This commit is contained in:
如梦技术
2019-07-25 13:02:37 +08:00
committed by Spencer Gibb
parent f7b9bb76c8
commit 1879074d6d
2 changed files with 18 additions and 1 deletions

View File

@@ -453,7 +453,7 @@ public class ProxyExchange<T> {
protected static class BodyGrabber {
public Object body(@RequestBody Object body) {
public Object body(@RequestBody(required = false) Object body) {
return body;
}

View File

@@ -235,6 +235,12 @@ public class ProductionConfigurationTests {
.isEqualTo("host=localhost;foobar");
}
@Test
public void noBody() throws Exception {
Foo foo = rest.postForObject("/proxy/no-body", null, Foo.class);
assertThat(foo.getName()).isEqualTo("hello");
}
@Test
@SuppressWarnings({ "Duplicates", "unchecked" })
public void headers() throws Exception {
@@ -351,6 +357,12 @@ public class ProductionConfigurationTests {
.body(response.getBody().iterator().next()));
}
@PostMapping("/proxy/no-body")
public ResponseEntity<Foo> noBody(ProxyExchange<Foo> proxy) throws Exception {
return proxy.uri(home.toString() + "/foos")
.post();
}
@GetMapping("/forward/**")
public void forward(ProxyExchange<?> proxy) throws Exception {
String path = proxy.path("/forward");
@@ -413,6 +425,11 @@ public class ProductionConfigurationTests {
return Arrays.asList(new Foo("hello"));
}
@PostMapping("/foos")
public Foo postFoos() {
return new Foo("hello");
}
@GetMapping("/foos/{id}")
public Foo foo(@PathVariable Integer id, @RequestHeader HttpHeaders headers) {
String custom = headers.getFirst("X-Custom");