use of io.servicetalk.http.api.RedirectConfigBuilder in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method invalidLocation.
@Test
void invalidLocation() {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY, "://non-relative.servicetalk.io"), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().allowNonRelativeRedirects(true).build());
ExecutionException e = assertThrows(ExecutionException.class, () -> client.request(newRequest(client, GET)).toFuture().get());
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
}
use of io.servicetalk.http.api.RedirectConfigBuilder in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method redirectFromRelativeFormToAbsoluteFormNonRelativeLocation.
@ParameterizedTest(name = "{displayName} [{index}] allowNonRelativeRedirects={0}")
@ValueSource(booleans = { true, false })
void redirectFromRelativeFormToAbsoluteFormNonRelativeLocation(boolean allowNonRelativeRedirects) throws Exception {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY, "http://non-relative.servicetalk.io"), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().allowNonRelativeRedirects(allowNonRelativeRedirects).build());
StreamingHttpRequest request = newRequest(client, GET);
if (allowNonRelativeRedirects) {
verifyRedirected(client, request, false, true);
} else {
verifyDoesNotRedirect(client, request, MOVED_PERMANENTLY);
verifyRedirectResponsePayloadsDrained(false);
}
}
use of io.servicetalk.http.api.RedirectConfigBuilder in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method redirectResponseWithEmptyLocation.
@Test
void redirectResponseWithEmptyLocation() throws Exception {
when(httpClient.request(any())).thenReturn(// no "location" header returned
succeeded(reqRespFactory.newResponse(MOVED_PERMANENTLY)), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().build());
verifyResponse(client, newRequest(client, GET), MOVED_PERMANENTLY, -1, 1, GET);
}
use of io.servicetalk.http.api.RedirectConfigBuilder in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method failedResponse.
@Test
void failedResponse() {
when(httpClient.request(any())).thenReturn(failed(DELIBERATE_EXCEPTION));
StreamingHttpClient client = newClient(new RedirectConfigBuilder().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.RedirectConfigBuilder in project servicetalk by apple.
the class RedirectingHttpRequesterFilterTest method getRequestForRedirectWithAbsoluteFormRequestTargetToRelativeLocation.
@ParameterizedTest(name = "{displayName} [{index}] allowNonRelativeRedirects={0}")
@ValueSource(booleans = { true, false })
void getRequestForRedirectWithAbsoluteFormRequestTargetToRelativeLocation(boolean allowNonRelativeRedirects) throws Exception {
when(httpClient.request(any())).thenReturn(redirectResponse(MOVED_PERMANENTLY), okResponse());
StreamingHttpClient client = newClient(new RedirectConfigBuilder().allowNonRelativeRedirects(allowNonRelativeRedirects).build());
StreamingHttpRequest request = newRequest(client, GET).requestTarget("http://servicetalk.io/path");
verifyRedirected(client, request, true, allowNonRelativeRedirects);
}
Aggregations