Search in sources :

Example 16 with StreamingHttpClient

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));
}
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 17 with StreamingHttpClient

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

Example 18 with StreamingHttpClient

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);
}
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 19 with StreamingHttpClient

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));
}
Also used : StreamingHttpClientFilterFactory(io.servicetalk.http.api.StreamingHttpClientFilterFactory) MULTIPLE_CHOICES(io.servicetalk.http.api.HttpResponseStatus.MULTIPLE_CHOICES) HttpRequestMethod(io.servicetalk.http.api.HttpRequestMethod) LOCATION(io.servicetalk.http.api.HttpHeaderNames.LOCATION) Matchers.not(org.hamcrest.Matchers.not) CONTENT_TYPE(io.servicetalk.http.api.HttpHeaderNames.CONTENT_TYPE) BAD_REQUEST(io.servicetalk.http.api.HttpResponseStatus.BAD_REQUEST) TEMPORARY_REDIRECT(io.servicetalk.http.api.HttpResponseStatus.TEMPORARY_REDIRECT) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HEAD(io.servicetalk.http.api.HttpRequestMethod.HEAD) RedirectConfig(io.servicetalk.http.api.RedirectConfig) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Executor(io.servicetalk.concurrent.api.Executor) FOUND(io.servicetalk.http.api.HttpResponseStatus.FOUND) SEE_OTHER(io.servicetalk.http.api.HttpResponseStatus.SEE_OTHER) StreamingHttpRequestFactory(io.servicetalk.http.api.StreamingHttpRequestFactory) PUT(io.servicetalk.http.api.HttpRequestMethod.PUT) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) FilterFactoryUtils.appendClientFilterFactory(io.servicetalk.http.api.FilterFactoryUtils.appendClientFilterFactory) Mockito.clearInvocations(org.mockito.Mockito.clearInvocations) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) TRANSFER_ENCODING(io.servicetalk.http.api.HttpHeaderNames.TRANSFER_ENCODING) CONNECT(io.servicetalk.http.api.HttpRequestMethod.CONNECT) POST(io.servicetalk.http.api.HttpRequestMethod.POST) StatelessTrailersTransformer(io.servicetalk.http.api.StatelessTrailersTransformer) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) CONTENT_LENGTH(io.servicetalk.http.api.HttpHeaderNames.CONTENT_LENGTH) Matchers.startsWith(org.hamcrest.Matchers.startsWith) DefaultHttpHeadersFactory(io.servicetalk.http.api.DefaultHttpHeadersFactory) Test(org.junit.jupiter.api.Test) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Buffer(io.servicetalk.buffer.api.Buffer) CONTINUE(io.servicetalk.http.api.HttpResponseStatus.CONTINUE) PATCH(io.servicetalk.http.api.HttpRequestMethod.PATCH) NOT_MODIFIED(io.servicetalk.http.api.HttpResponseStatus.NOT_MODIFIED) Matchers.is(org.hamcrest.Matchers.is) Queue(java.util.Queue) Matchers.endsWith(org.hamcrest.Matchers.endsWith) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) DEFAULT_ALLOCATOR(io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) TestStreamingHttpClient.from(io.servicetalk.http.api.TestStreamingHttpClient.from) HttpHeaders(io.servicetalk.http.api.HttpHeaders) StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) ArgumentCaptor(org.mockito.ArgumentCaptor) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HOST(io.servicetalk.http.api.HttpHeaderNames.HOST) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) Matchers.contentEqualTo(io.servicetalk.buffer.api.Matchers.contentEqualTo) OPTIONS(io.servicetalk.http.api.HttpRequestMethod.OPTIONS) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Publisher.from(io.servicetalk.concurrent.api.Publisher.from) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) DELETE(io.servicetalk.http.api.HttpRequestMethod.DELETE) USE_PROXY(io.servicetalk.http.api.HttpResponseStatus.USE_PROXY) Nullable(javax.annotation.Nullable) CHUNKED(io.servicetalk.http.api.HttpHeaderValues.CHUNKED) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) ValueSource(org.junit.jupiter.params.provider.ValueSource) Mockito.ignoreStubs(org.mockito.Mockito.ignoreStubs) INTERNAL_SERVER_ERROR(io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) StreamingHttpRequestResponseFactory(io.servicetalk.http.api.StreamingHttpRequestResponseFactory) Single(io.servicetalk.concurrent.api.Single) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) OK(io.servicetalk.http.api.HttpResponseStatus.OK) GET(io.servicetalk.http.api.HttpRequestMethod.GET) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) ACCEPT_ENCODING(io.servicetalk.http.api.HttpHeaderNames.ACCEPT_ENCODING) US_ASCII(java.nio.charset.StandardCharsets.US_ASCII) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) String.valueOf(java.lang.String.valueOf) ArgumentCaptor.forClass(org.mockito.ArgumentCaptor.forClass) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) PERMANENT_REDIRECT(io.servicetalk.http.api.HttpResponseStatus.PERMANENT_REDIRECT) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) Single.failed(io.servicetalk.concurrent.api.Single.failed) StreamingHttpClientFilterFactory(io.servicetalk.http.api.StreamingHttpClientFilterFactory) HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) HTTP_1_1(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_1) MOVED_PERMANENTLY(io.servicetalk.http.api.HttpResponseStatus.MOVED_PERMANENTLY) DefaultStreamingHttpRequestResponseFactory(io.servicetalk.http.api.DefaultStreamingHttpRequestResponseFactory) HTTP_1_0(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_0) TRACE(io.servicetalk.http.api.HttpRequestMethod.TRACE) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) HttpExecutionContext(io.servicetalk.http.api.HttpExecutionContext) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse)

Example 20 with StreamingHttpClient

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);
}
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)

Aggregations

StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)76 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)48 RedirectConfigBuilder (io.servicetalk.http.api.RedirectConfigBuilder)33 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)31 Test (org.junit.jupiter.api.Test)31 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)27 Buffer (io.servicetalk.buffer.api.Buffer)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)22 StreamingHttpConnection (io.servicetalk.http.api.StreamingHttpConnection)19 SingleAddressHttpClientBuilder (io.servicetalk.http.api.SingleAddressHttpClientBuilder)16 HttpServerContext (io.servicetalk.http.api.HttpServerContext)15 InetSocketAddress (java.net.InetSocketAddress)15 ServerContext (io.servicetalk.transport.api.ServerContext)13 Single (io.servicetalk.concurrent.api.Single)12 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 ExecutionException (java.util.concurrent.ExecutionException)11 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)10 HostAndPort (io.servicetalk.transport.api.HostAndPort)10 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)9