use of io.helidon.webclient.WebClientRequestBuilder 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.WebClientRequestBuilder in project helidon by oracle.
the class MaxPayloadSizeTest method testContentLengthExceeded.
/**
* If content length is greater than max, a 413 must be returned. No actual
* payload in this case.
*/
@Test
public void testContentLengthExceeded() {
WebClientRequestBuilder builder = webClient.post();
// over max
builder.headers().add("Content-Length", "512");
WebClientResponse response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).request().await(5, TimeUnit.SECONDS);
assertThat(response.status().code(), is(Http.Status.REQUEST_ENTITY_TOO_LARGE_413.code()));
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class MaxPayloadSizeTest method testActualLengthExceededWithPayload.
/**
* If actual payload length is greater than max when using chunked encoding, a 413
* must be returned. Given that this publisher can write up to 3 chunks (using chunked
* encoding), we also check for a connection reset exception condition.
*/
@Test
public void testActualLengthExceededWithPayload() {
try {
WebClientRequestBuilder builder = webClient.post();
WebClientResponse response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(new PayloadPublisher(PAYLOAD, 3)).await(5, TimeUnit.SECONDS);
assertThat(response.status().code(), is(Http.Status.REQUEST_ENTITY_TOO_LARGE_413.code()));
} catch (CompletionException e) {
assertTrue(isConnectionReset(e));
}
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class MaxPayloadSizeTest method testMixedGoodAndBadPayloads.
/**
* Tests mixed requests, some that exceed limits, others that do not.
*/
@Test
public void testMixedGoodAndBadPayloads() {
WebClientRequestBuilder builder = webClient.post();
WebClientResponse response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(PAYLOAD.substring(0, 100)).await(5, TimeUnit.SECONDS);
assertThat(response.status().code(), is(Http.Status.OK_200.code()));
builder = webClient.post();
response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(new PayloadPublisher(PAYLOAD, 1)).await(5, TimeUnit.SECONDS);
assertThat(response.status().code(), is(Http.Status.REQUEST_ENTITY_TOO_LARGE_413.code()));
builder = webClient.post();
response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(PAYLOAD.substring(0, (int) MAX_PAYLOAD_SIZE)).await(5, TimeUnit.SECONDS);
assertThat(response.status().code(), is(Http.Status.OK_200.code()));
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class TestHttpParseFineTuning method testHeaderName.
private void testHeaderName(WebClient client, String headerName, boolean success) {
WebClientRequestBuilder builder = client.get();
builder.headers().add(headerName, "some random value");
WebClientResponse response = builder.path("/static/static-content.txt").request().await(10, TimeUnit.SECONDS);
if (success) {
assertThat("Header '" + headerName + "' should have passed", response.status(), is(Http.Status.OK_200));
assertThat("This request should return content of static-content.txt", response.content().as(String.class).await(10, TimeUnit.SECONDS), is("Hi"));
} else {
assertThat("Header '" + headerName + "' should have failed", response.status(), is(Http.Status.BAD_REQUEST_400));
}
}
Aggregations