Search in sources :

Example 16 with Headers

use of io.helidon.common.http.Headers in project helidon by oracle.

the class AbstractCorsTest method test2PreFlightAllowedOrigin.

@Test
void test2PreFlightAllowedOrigin() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().options().path(path(SERVICE_2));
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, "http://foo.bar");
    headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
    WebClientResponse res = reqBuilder.request().toCompletableFuture().get();
    assertThat(res.status(), is(Http.Status.OK_200));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is("http://foo.bar")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_CREDENTIALS), present(is("true")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_METHODS), present(is("PUT")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), notPresent());
    assertThat(res.headers().first(ACCESS_CONTROL_MAX_AGE), notPresent());
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 17 with Headers

use of io.helidon.common.http.Headers in project helidon by oracle.

the class AbstractCorsTest method test2ActualAllowedOrigin.

@Test
void test2ActualAllowedOrigin() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().put().path(path(SERVICE_2)).contentType(MediaType.TEXT_PLAIN);
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, "http://foo.bar");
    WebClientResponse res = reqBuilder.submit("").toCompletableFuture().get();
    assertThat(res.status(), is(Http.Status.OK_200));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is("http://foo.bar")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_CREDENTIALS), present(is("true")));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 18 with Headers

use of io.helidon.common.http.Headers in project helidon by oracle.

the class AbstractCorsTest method runTest1PreFlightAllowedOrigin.

WebClientResponse runTest1PreFlightAllowedOrigin() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().options().path(path(contextRoot(), SERVICE_1));
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, fooOrigin());
    headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
    WebClientResponse res = reqBuilder.request().toCompletableFuture().get();
    return res;
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder)

Example 19 with Headers

use of io.helidon.common.http.Headers in project helidon by oracle.

the class AbstractCorsTest method test2PreFlightAllowedHeaders3.

@Test
void test2PreFlightAllowedHeaders3() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().options().path(path(SERVICE_2));
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, "http://foo.bar");
    headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
    headers.add(ACCESS_CONTROL_REQUEST_HEADERS, "X-foo, X-bar");
    headers.add(ACCESS_CONTROL_REQUEST_HEADERS, "X-foo, X-bar");
    WebClientResponse res = reqBuilder.request().toCompletableFuture().get();
    assertThat(res.status(), is(Http.Status.OK_200));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is("http://foo.bar")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_CREDENTIALS), present(is("true")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_METHODS), present(is("PUT")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), present(containsString("X-foo")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), present(containsString("X-bar")));
    assertThat(res.headers().first(ACCESS_CONTROL_MAX_AGE), notPresent());
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 20 with Headers

use of io.helidon.common.http.Headers in project helidon by oracle.

the class AbstractCorsTest method test2PreFlightAllowedHeaders1.

@Test
void test2PreFlightAllowedHeaders1() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().options().path(path(contextRoot(), SERVICE_2));
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, fooOrigin());
    headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
    headers.add(ACCESS_CONTROL_REQUEST_HEADERS, fooHeader());
    WebClientResponse res = reqBuilder.request().toCompletableFuture().get();
    assertThat(res.status(), is(Http.Status.OK_200));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is(fooOrigin())));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_CREDENTIALS), present(is("true")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_METHODS), present(is("PUT")));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), present(containsString(fooHeader())));
    assertThat(res.headers().first(ACCESS_CONTROL_MAX_AGE), notPresent());
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

Headers (io.helidon.common.http.Headers)25 WebClientRequestBuilder (io.helidon.webclient.WebClientRequestBuilder)24 WebClientResponse (io.helidon.webclient.WebClientResponse)24 Test (org.junit.jupiter.api.Test)23 Order (org.junit.jupiter.api.Order)8 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)8 Http (io.helidon.common.http.Http)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 WebClient (io.helidon.webclient.WebClient)2 WebClientResponseHeaders (io.helidon.webclient.WebClientResponseHeaders)2 WebServer (io.helidon.webserver.WebServer)2 GenericType (io.helidon.common.GenericType)1 Context (io.helidon.common.context.Context)1 Contexts (io.helidon.common.context.Contexts)1 DataChunk (io.helidon.common.http.DataChunk)1 HttpRequest (io.helidon.common.http.HttpRequest)1 MediaType (io.helidon.common.http.MediaType)1 Parameters (io.helidon.common.http.Parameters)1 Single (io.helidon.common.reactive.Single)1 MessageBodyReadableContent (io.helidon.media.common.MessageBodyReadableContent)1