Search in sources :

Example 1 with RedirectConfig

use of io.servicetalk.http.api.RedirectConfig in project servicetalk by apple.

the class RedirectingHttpRequesterFilterTest method overrideAllowedMethods.

@Test
void overrideAllowedMethods() throws Exception {
    RedirectConfig config = new RedirectConfigBuilder().allowedMethods(POST).build();
    testRedirected(POST, MOVED_PERMANENTLY, config);
    testNoRedirectWasDone(GET, MOVED_PERMANENTLY, config);
    testNoRedirectWasDone(HEAD, MOVED_PERMANENTLY, config);
}
Also used : RedirectConfig(io.servicetalk.http.api.RedirectConfig) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with RedirectConfig

use of io.servicetalk.http.api.RedirectConfig 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)

Aggregations

RedirectConfig (io.servicetalk.http.api.RedirectConfig)2 RedirectConfigBuilder (io.servicetalk.http.api.RedirectConfigBuilder)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Buffer (io.servicetalk.buffer.api.Buffer)1 Matchers.contentEqualTo (io.servicetalk.buffer.api.Matchers.contentEqualTo)1 DEFAULT_ALLOCATOR (io.servicetalk.buffer.netty.BufferAllocators.DEFAULT_ALLOCATOR)1 Executor (io.servicetalk.concurrent.api.Executor)1 ExecutorExtension (io.servicetalk.concurrent.api.ExecutorExtension)1 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)1 Single (io.servicetalk.concurrent.api.Single)1 Single.failed (io.servicetalk.concurrent.api.Single.failed)1 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)1 TestPublisher (io.servicetalk.concurrent.api.TestPublisher)1 DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)1 DefaultHttpHeadersFactory (io.servicetalk.http.api.DefaultHttpHeadersFactory)1 DefaultStreamingHttpRequestResponseFactory (io.servicetalk.http.api.DefaultStreamingHttpRequestResponseFactory)1 FilterFactoryUtils.appendClientFilterFactory (io.servicetalk.http.api.FilterFactoryUtils.appendClientFilterFactory)1 HttpExecutionContext (io.servicetalk.http.api.HttpExecutionContext)1 ACCEPT_ENCODING (io.servicetalk.http.api.HttpHeaderNames.ACCEPT_ENCODING)1