use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class AbstractCorsTest method test2PreFlightForbiddenHeader.
@Test
void test2PreFlightForbiddenHeader() 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, X-oops");
WebClientResponse res = reqBuilder.request().toCompletableFuture().get();
Http.ResponseStatus status = res.status();
assertThat(status.code(), is(Http.Status.FORBIDDEN_403.code()));
assertThat(status.reasonPhrase(), is("CORS headers not in allowed list"));
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class AbstractCorsTest method test2PreFlightAllowedHeaders2.
@Test
void test2PreFlightAllowedHeaders2() 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");
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());
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class AbstractCorsTest method test1ActualAllowedOrigin.
@Test
void test1ActualAllowedOrigin() throws ExecutionException, InterruptedException {
WebClientRequestBuilder reqBuilder = client().put().path(path(SERVICE_1)).contentType(MediaType.TEXT_PLAIN);
Headers headers = reqBuilder.headers();
headers.add(ORIGIN, "http://foo.bar");
headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
WebClientResponse res = reqBuilder.submit("").toCompletableFuture().get();
assertThat(res.status(), is(Http.Status.OK_200));
assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is("*")));
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class ContextLifeCycleTest method testContextMediaSupport.
@Test
void testContextMediaSupport() {
Handler handler = (req, res) -> {
String cid = req.context().id();
req.content().as(String.class).thenAccept(payload -> {
if (cid.equals(contextId())) {
res.send();
} else {
res.status(400).send();
}
});
};
WebServer webServer = WebServer.builder(Routing.builder().post(handler)).build().start().await(10, TimeUnit.SECONDS);
ResponseStatus responseStatus = WebClient.builder().baseUri("http://localhost:" + webServer.port()).build().post().submit("some-payload").map(WebClientResponse::status).onTerminate(webServer::shutdown).await(10, TimeUnit.SECONDS);
assertThat(responseStatus.code(), is(200));
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class ContextLifeCycleTest method testContextReactive.
@Test
void testContextReactive() {
Handler handler = (req, res) -> {
String cid = req.context().id();
req.content().subscribe(new Subscriber<>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(Long.MAX_VALUE);
}
@Override
public void onNext(DataChunk item) {
item.release();
if (!cid.equals(contextId())) {
throw new IllegalStateException("Context invalid");
}
}
@Override
public void onError(Throwable throwable) {
res.send(throwable);
}
@Override
public void onComplete() {
if (!cid.equals(contextId())) {
res.send(new IllegalStateException("Context invalid"));
} else {
res.send();
}
}
});
};
WebServer webServer = WebServer.builder(Routing.builder().post(handler)).build().start().await(10, TimeUnit.SECONDS);
ResponseStatus responseStatus = WebClient.builder().baseUri("http://localhost:" + webServer.port()).build().post().submit("some-payload").map(WebClientResponse::status).onTerminate(webServer::shutdown).await(10, TimeUnit.SECONDS);
assertThat(responseStatus.code(), is(200));
}
Aggregations