Skip to content

Commit

Permalink
Updates to use WHAT_WG uri parser type.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Oct 11, 2024
1 parent cf5171b commit 766e3e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.DefaultUriBuilderFactory;

import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

Expand All @@ -56,8 +57,10 @@ public static void afterClass() {

@Test
public void requestsToManagementPortReturn404() {
String baseUrl = "http://localhost:" + managementPort;
testClient.mutate()
.baseUrl("http://localhost:" + managementPort)
.uriBuilderFactory(new DefaultUriBuilderFactory(baseUrl))
.baseUrl(baseUrl)
.build()
.get()
.uri("/get")
Expand All @@ -69,8 +72,10 @@ public void requestsToManagementPortReturn404() {
@Test
public void requestsToManagementPortAndHostHeaderReturn404() {
String host = "example.com:8888";
String baseUrl = "http://localhost:" + managementPort;
testClient.mutate()
.baseUrl("http://localhost:" + managementPort)
.uriBuilderFactory(new DefaultUriBuilderFactory(baseUrl))
.baseUrl(baseUrl)
.build()
.get()
.uri("/get")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriComponentsBuilder;

import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_HANDLER_MAPPER_ATTR;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR;
Expand Down Expand Up @@ -76,7 +78,12 @@ public void setup() throws Exception {
protected void setup(ClientHttpConnector httpConnector, String baseUri) {
this.baseUri = baseUri;
this.webClient = WebClient.builder().clientConnector(httpConnector).baseUrl(this.baseUri).build();
this.testClient = WebTestClient.bindToServer(httpConnector).baseUrl(this.baseUri).build();
DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory(this.baseUri);
uriBuilderFactory.setParserType(UriComponentsBuilder.ParserType.WHAT_WG);
this.testClient = WebTestClient.bindToServer(httpConnector)
.uriBuilderFactory(uriBuilderFactory)
.baseUrl(this.baseUri)
.build();
}

@Configuration(proxyBeanMethods = false)
Expand Down

0 comments on commit 766e3e0

Please sign in to comment.