use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class ExpectContinueTest method expectContinueThenFailure.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinueThenFailure(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
requestReceived.countDown();
sendContinue.await();
StringBuilder sb = new StringBuilder();
request.payloadBody().forEach(chunk -> sb.append(chunk.toString(US_ASCII)));
returnResponse.await();
try (HttpPayloadWriter<Buffer> writer = response.status(UNPROCESSABLE_ENTITY).sendMetaData()) {
writer.write(ctx.executionContext().bufferAllocator().fromAscii(sb));
}
});
StreamingHttpClient client = createClient(serverContext, protocol);
StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
BufferAllocator allocator = connection.executionContext().bufferAllocator();
TestPublisher<Buffer> payload = new TestPublisher.Builder<Buffer>().singleSubscriber().build();
connection.request(newRequest(connection, withCL, false, payload)).subscribe(responses::add);
requestReceived.await();
assertThat("Unexpected subscribe to payload body before 100 (Continue)", payload.isSubscribed(), is(false));
sendContinue.countDown();
sendRequestPayload(payload, allocator);
returnResponse.countDown();
assertResponse(UNPROCESSABLE_ENTITY, PAYLOAD + PAYLOAD);
sendFollowUpRequest(connection, withCL, allocator, UNPROCESSABLE_ENTITY);
}
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method shouldRedirectThrows.
@Test
void shouldRedirectThrows() {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().redirectPredicate((relative, count, request, response) -> {
throw DELIBERATE_EXCEPTION;
}).build());
ExecutionException e = assertThrows(ExecutionException.class, () -> client.request(newRequest(client, GET)).toFuture().get());
assertThat(e.getCause(), sameInstance(DELIBERATE_EXCEPTION));
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method redirectForOnlyRelativeWithAbsoluteFormRelativeLocationWithPort.
@Test
void redirectForOnlyRelativeWithAbsoluteFormRelativeLocationWithPort() throws Exception {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY, "http://servicetalk.io:80"), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().allowNonRelativeRedirects(false).build());
verifyRedirected(client, newRequest(client, GET).setHeader(HOST, "servicetalk.io:80"), true, false);
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method multipleFollowUpRedirects.
@Test
void multipleFollowUpRedirects() throws Exception {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY, 1), redirectResponse(MOVED_PERMANENTLY, 2), redirectResponse(MOVED_PERMANENTLY, 3), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().build());
verifyResponse(client, newRequest(client, GET), OK, -1, 4, GET);
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method misConfigureRedirectOfHeadersAndMessageBodyForNonRelativeRedirects.
@Test
void misConfigureRedirectOfHeadersAndMessageBodyForNonRelativeRedirects() throws Exception {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY, "http://non-relative.servicetalk.io"), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().allowNonRelativeRedirects(true).headersToRedirect("Unknown-header").redirectPayloadBody(false).trailersToRedirect("Unknown-trailer").build());
verifyRedirected(client, newRequest(client, GET), false, true);
}
Aggregations