Search in sources :

Example 21 with RedirectConfigBuilder

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));
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with RedirectConfigBuilder

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);
    }
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with RedirectConfigBuilder

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);
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with RedirectConfigBuilder

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));
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with RedirectConfigBuilder

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);
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RedirectConfigBuilder (io.servicetalk.http.api.RedirectConfigBuilder)27 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)23 Test (org.junit.jupiter.api.Test)17 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)10 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 ExecutionException (java.util.concurrent.ExecutionException)5 CUSTOM_HEADER (io.servicetalk.examples.http.redirects.RedirectingServer.CUSTOM_HEADER)2 NON_SECURE_SERVER_PORT (io.servicetalk.examples.http.redirects.RedirectingServer.NON_SECURE_SERVER_PORT)2 HttpClient (io.servicetalk.http.api.HttpClient)2 LOCATION (io.servicetalk.http.api.HttpHeaderNames.LOCATION)2 GET (io.servicetalk.http.api.HttpRequestMethod.GET)2 POST (io.servicetalk.http.api.HttpRequestMethod.POST)2 RedirectConfig (io.servicetalk.http.api.RedirectConfig)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Buffer (io.servicetalk.buffer.api.Buffer)1 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)1 ServiceDiscoverer (io.servicetalk.client.api.ServiceDiscoverer)1 ServiceDiscovererEvent (io.servicetalk.client.api.ServiceDiscovererEvent)1 AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)1