Calls RewriteFunction even if body is empty.
fixes gh-1219 fixes gh-1220
This commit is contained in:
committed by
Spencer Gibb
parent
2e890864bd
commit
7eaecedd5e
@@ -99,6 +99,31 @@ public class GatewaySampleApplication {
|
||||
})
|
||||
).uri(uri)
|
||||
)
|
||||
.route("rewrite_empty_response", r -> r.host("*.rewriteemptyresponse.org")
|
||||
.filters(f -> f.prefixPath("/httpbin")
|
||||
.addResponseHeader("X-TestHeader", "rewrite_empty_response")
|
||||
.modifyResponseBody(String.class, String.class,
|
||||
(exchange, s) -> {
|
||||
if (s == null) {
|
||||
return Mono.just("emptybody");
|
||||
}
|
||||
return Mono.just(s.toUpperCase());
|
||||
})
|
||||
|
||||
).uri(uri)
|
||||
)
|
||||
.route("rewrite_response_fail_supplier", r -> r.host("*.rewriteresponsewithfailsupplier.org")
|
||||
.filters(f -> f.prefixPath("/httpbin")
|
||||
.addResponseHeader("X-TestHeader", "rewrite_response_fail_supplier")
|
||||
.modifyResponseBody(String.class, String.class,
|
||||
(exchange, s) -> {
|
||||
if (s == null) {
|
||||
return Mono.error(new IllegalArgumentException("this should not happen"));
|
||||
}
|
||||
return Mono.just(s.toUpperCase());
|
||||
})
|
||||
).uri(uri)
|
||||
)
|
||||
.route("rewrite_response_obj", r -> r.host("*.rewriteresponseobj.org")
|
||||
.filters(f -> f.prefixPath("/httpbin")
|
||||
.addResponseHeader("X-TestHeader", "rewrite_response_obj")
|
||||
|
||||
@@ -130,6 +130,29 @@ public class GatewaySampleApplicationTests {
|
||||
.containsEntry("DATA", "HELLO"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void rewriteResponseEmptyBodyToStringWorks() {
|
||||
webClient.post().uri("/post/empty").header("Host", "www.rewriteemptyresponse.org")
|
||||
.exchange().expectStatus().isOk().expectHeader()
|
||||
.valueEquals("X-TestHeader", "rewrite_empty_response")
|
||||
.expectBody(String.class)
|
||||
.consumeWith(result -> assertThat(result.getResponseBody())
|
||||
.isEqualTo("emptybody"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void emptyBodySupplierNotCalledWhenBodyPresent() {
|
||||
webClient.post().uri("/post")
|
||||
.header("Host", "www.rewriteresponsewithfailsupplier.org")
|
||||
.bodyValue("hello").exchange().expectStatus().isOk().expectHeader()
|
||||
.valueEquals("X-TestHeader", "rewrite_response_fail_supplier")
|
||||
.expectBody(Map.class)
|
||||
.consumeWith(result -> assertThat(result.getResponseBody())
|
||||
.containsEntry("DATA", "HELLO"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void rewriteResponeBodyObjectWorks() {
|
||||
|
||||
Reference in New Issue
Block a user