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 http10WithoutHostHeader.
@Test
void http10WithoutHostHeader() throws Exception {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().build());
StreamingHttpRequest request = newRequest(client, GET).version(HTTP_1_0);
request.headers().remove(HOST);
verifyRedirected(client, request, true, false);
}
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);
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method newClient.
private StreamingHttpClient newClient(RedirectConfig config, StreamingHttpClientFilterFactory... other) {
StreamingHttpClientFilterFactory result = new RedirectingHttpRequesterFilter(config);
for (StreamingHttpClientFilterFactory next : other) {
result = appendClientFilterFactory(result, next);
}
StreamingHttpClientFilterFactory mockResponse = client -> new StreamingHttpClientFilter(client) {
@Override
protected Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final StreamingHttpRequest request) {
return httpClient.request(request);
}
};
return from(reqRespFactory, mock(HttpExecutionContext.class), appendClientFilterFactory(result, mockResponse));
}
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);
}
Aggregations