Browse Source

removes unneeded cast to GatewayServerResponse for header manipulation.

pull/3006/head
sgibb 2 years ago
parent
commit
1863ade599
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 12
      spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/AfterFilterFunctions.java
  2. 5
      spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java

12
spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/AfterFilterFunctions.java

@ -30,20 +30,16 @@ public interface AfterFilterFunctions { @@ -30,20 +30,16 @@ public interface AfterFilterFunctions {
static BiFunction<ServerRequest, ServerResponse, ServerResponse> addResponseHeader(String name, String... values) {
return (request, response) -> {
if (response instanceof GatewayServerResponse res) {
String[] expandedValues = MvcUtils.expandMultiple(request, values);
res.headers().addAll(name, Arrays.asList(expandedValues));
}
String[] expandedValues = MvcUtils.expandMultiple(request, values);
response.headers().addAll(name, Arrays.asList(expandedValues));
return response;
};
}
static BiFunction<ServerRequest, ServerResponse, ServerResponse> setResponseHeader(String name, String value) {
return (request, response) -> {
if (response instanceof GatewayServerResponse res) {
String expandedValue = MvcUtils.expand(request, value);
res.headers().set(name, expandedValue);
}
String expandedValue = MvcUtils.expand(request, value);
response.headers().set(name, expandedValue);
return response;
};
}

5
spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/ServerMvcIntegrationTests.java

@ -418,8 +418,8 @@ public class ServerMvcIntegrationTests { @@ -418,8 +418,8 @@ public class ServerMvcIntegrationTests {
@Test
public void removeRequestParameterWorks() {
restClient.get().uri("/anything/removerequestparameter?foo=bar").header("test", "removerequestparam").exchange().expectStatus()
.isOk().expectBody(Map.class).consumeWith(res -> {
restClient.get().uri("/anything/removerequestparameter?foo=bar").header("test", "removerequestparam").exchange()
.expectStatus().isOk().expectBody(Map.class).consumeWith(res -> {
Map<String, Object> map = res.getResponseBody();
Map<String, Object> args = getMap(map, "args");
assertThat(args).doesNotContainKey("foo");
@ -733,6 +733,7 @@ public class ServerMvcIntegrationTests { @@ -733,6 +733,7 @@ public class ServerMvcIntegrationTests {
.build();
// @formatter:on
}
}
@RestController

Loading…
Cancel
Save