Search in sources :

Example 1 with WebClientResponseHeaders

use of io.helidon.webclient.WebClientResponseHeaders in project helidon by oracle.

the class TestDefaultCorsSupport method testOptionsWithCors.

@Test
void testOptionsWithCors() throws ExecutionException, InterruptedException {
    WebServer server = null;
    WebClient client;
    try {
        server = WebServer.create(prepRouting(true)).start().toCompletableFuture().get();
        client = WebClient.builder().baseUri("http://localhost:" + server.port()).get();
        WebClientRequestBuilder reqBuilder = client.options().path("/greet");
        Headers h = reqBuilder.headers();
        h.add("Origin", "http://foo.com");
        h.add("Host", "bar.com");
        WebClientResponse response = reqBuilder.submit().toCompletableFuture().get();
        WebClientResponseHeaders headers = response.headers();
        List<String> allowOrigins = headers.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
        assertThat(allowOrigins, contains("*"));
    } finally {
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebServer(io.helidon.webserver.WebServer) WebClientResponseHeaders(io.helidon.webclient.WebClientResponseHeaders) Headers(io.helidon.common.http.Headers) WebClient(io.helidon.webclient.WebClient) WebClientResponseHeaders(io.helidon.webclient.WebClientResponseHeaders) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with WebClientResponseHeaders

use of io.helidon.webclient.WebClientResponseHeaders in project helidon by oracle.

the class TestDefaultCorsSupport method testOptionsWithoutCors.

@Test
void testOptionsWithoutCors() throws ExecutionException, InterruptedException {
    WebServer server = null;
    WebClient client;
    try {
        server = WebServer.create(prepRouting(false)).start().toCompletableFuture().get();
        client = WebClient.builder().baseUri("http://localhost:" + server.port()).get();
        WebClientRequestBuilder reqBuilder = client.options().path("/greet");
        Headers h = reqBuilder.headers();
        h.add("Origin", "http://foo.com");
        h.add("Host", "bar.com");
        WebClientResponse response = reqBuilder.submit().toCompletableFuture().get();
        WebClientResponseHeaders headers = response.headers();
        List<String> allowOrigins = headers.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
        assertThat(allowOrigins.size(), is(0));
    } finally {
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebServer(io.helidon.webserver.WebServer) WebClientResponseHeaders(io.helidon.webclient.WebClientResponseHeaders) Headers(io.helidon.common.http.Headers) WebClient(io.helidon.webclient.WebClient) WebClientResponseHeaders(io.helidon.webclient.WebClientResponseHeaders) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Headers (io.helidon.common.http.Headers)2 WebClient (io.helidon.webclient.WebClient)2 WebClientRequestBuilder (io.helidon.webclient.WebClientRequestBuilder)2 WebClientResponse (io.helidon.webclient.WebClientResponse)2 WebClientResponseHeaders (io.helidon.webclient.WebClientResponseHeaders)2 WebServer (io.helidon.webserver.WebServer)2 Test (org.junit.jupiter.api.Test)2