Merge branch 'timpeeters-2.1.x' into 2.1.x
This commit is contained in:
@@ -119,6 +119,8 @@ public class NettyRoutingFilter implements GlobalFilter, Ordered {
|
||||
|
||||
Flux<HttpClientResponse> responseFlux = this.httpClient.headers(headers -> {
|
||||
headers.add(httpHeaders);
|
||||
// Will either be set below, or later by Netty
|
||||
headers.remove(HttpHeaders.HOST);
|
||||
if (preserveHost) {
|
||||
String host = request.getHeaders().getFirst(HttpHeaders.HOST);
|
||||
headers.add(HttpHeaders.HOST, host);
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
@@ -45,6 +46,18 @@ public class NettyRoutingFilterIntegrationTests extends BaseWebClientTests {
|
||||
.isEqualTo("Response took longer than timeout: PT3S");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outboundHostHeaderNotOverwrittenByInbound() {
|
||||
// different base url to have different host header in inbound / outbound requests
|
||||
// Host: 127.0.0.1 -> request to Gateway, Host: localhost -> request from Gateway,
|
||||
// resolved from lb://testservice
|
||||
WebTestClient client = testClient.mutate().baseUrl("http://127.0.0.1:" + port)
|
||||
.build();
|
||||
|
||||
client.get().uri("/headers").exchange().expectBody().jsonPath("$.headers.host")
|
||||
.isEqualTo("localhost:" + port);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootConfiguration
|
||||
@Import(DefaultTestConfig.class)
|
||||
|
||||
Reference in New Issue
Block a user