Search in sources :

Example 6 with OK

use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.

the class H2PriorKnowledgeFeatureParityTest method h2LayerFiltersOutProhibitedH1HeadersOnClientSide.

@Test
void h2LayerFiltersOutProhibitedH1HeadersOnClientSide() throws Exception {
    setUp(DEFAULT, true);
    serverAcceptorChannel = bindH2Server(serverEventLoopGroup, new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(final Channel ch) {
            ch.pipeline().addLast(new EchoHttp2Handler());
        }
    }, __ -> {
    }, identity());
    InetSocketAddress serverAddress = (InetSocketAddress) serverAcceptorChannel.localAddress();
    try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(HttpProtocol.HTTP_2.config).enableWireLogging("servicetalk-tests-wire-logger", LogLevel.TRACE, () -> true).executionStrategy(clientExecutionStrategy).buildBlocking()) {
        HttpResponse response = client.request(addProhibitedHeaders(client.post("/")).payloadBody(client.executionContext().bufferAllocator().fromAscii("content")));
        assertThat(response.status(), is(OK));
    }
}
Also used : TestUtils.assertNoAsyncErrors(io.servicetalk.test.resources.TestUtils.assertNoAsyncErrors) UnaryOperator.identity(java.util.function.UnaryOperator.identity) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) SingleSource(io.servicetalk.concurrent.SingleSource) StreamingHttpServiceFilterFactory(io.servicetalk.http.api.StreamingHttpServiceFilterFactory) UnaryOperator(java.util.function.UnaryOperator) LogLevel(io.servicetalk.logging.api.LogLevel) DefaultHttp2DataFrame(io.netty.handler.codec.http2.DefaultHttp2DataFrame) Disabled(org.junit.jupiter.api.Disabled) Matchers.hasItems(org.hamcrest.Matchers.hasItems) SourceAdapters.fromSource(io.servicetalk.concurrent.api.SourceAdapters.fromSource) H2StreamResetException(io.servicetalk.http.netty.NettyHttp2ExceptionUtils.H2StreamResetException) AsyncContext(io.servicetalk.concurrent.api.AsyncContext) HttpRequest(io.servicetalk.http.api.HttpRequest) Assumptions.assumeFalse(org.junit.jupiter.api.Assumptions.assumeFalse) Matchers.nullValue(org.hamcrest.Matchers.nullValue) PROTOCOL_ERROR(io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR) HttpCookiePair(io.servicetalk.http.api.HttpCookiePair) DefaultHttp2ResetFrame(io.netty.handler.codec.http2.DefaultHttp2ResetFrame) EXPECT(io.servicetalk.http.api.HttpHeaderNames.EXPECT) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) PrintWriter(java.io.PrintWriter) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) DefaultHttp2SettingsFrame(io.netty.handler.codec.http2.DefaultHttp2SettingsFrame) HttpClients.forSingleAddress(io.servicetalk.http.netty.HttpClients.forSingleAddress) HttpResponse(io.servicetalk.http.api.HttpResponse) Http2SettingsAckFrame(io.netty.handler.codec.http2.Http2SettingsAckFrame) TRANSFER_ENCODING(io.servicetalk.http.api.HttpHeaderNames.TRANSFER_ENCODING) POST(io.servicetalk.http.api.HttpRequestMethod.POST) BlockingQueue(java.util.concurrent.BlockingQueue) ChannelPipeline(io.netty.channel.ChannelPipeline) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) StatelessTrailersTransformer(io.servicetalk.http.api.StatelessTrailersTransformer) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) StreamingHttpConnectionFilter(io.servicetalk.http.api.StreamingHttpConnectionFilter) Arguments(org.junit.jupiter.params.provider.Arguments) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) UPGRADE(io.servicetalk.http.api.HttpHeaderNames.UPGRADE) CountDownLatch(java.util.concurrent.CountDownLatch) HttpSetCookie(io.servicetalk.http.api.HttpSetCookie) Buffer(io.servicetalk.buffer.api.Buffer) Stream(java.util.stream.Stream) Http2Headers(io.netty.handler.codec.http2.Http2Headers) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) COOKIE(io.servicetalk.http.api.HttpHeaderNames.COOKIE) Matchers.is(org.hamcrest.Matchers.is) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Processor(io.servicetalk.concurrent.PublisherSource.Processor) BuilderUtils.serverChannel(io.servicetalk.transport.netty.internal.BuilderUtils.serverChannel) TRAILER(io.netty.handler.codec.http.HttpHeaderNames.TRAILER) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HttpHeaders(io.servicetalk.http.api.HttpHeaders) ConsumableEvent(io.servicetalk.client.api.ConsumableEvent) StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) FilterableStreamingHttpConnection(io.servicetalk.http.api.FilterableStreamingHttpConnection) ArrayList(java.util.ArrayList) EMPTY_BUFFER(io.servicetalk.buffer.api.EmptyBuffer.EMPTY_BUFFER) MAX_CONCURRENCY(io.servicetalk.http.api.HttpEventKey.MAX_CONCURRENCY) HeaderUtils.isTransferEncodingChunked(io.servicetalk.http.api.HeaderUtils.isTransferEncodingChunked) HttpServiceContext(io.servicetalk.http.api.HttpServiceContext) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Processors(io.servicetalk.concurrent.api.Processors) BiConsumer(java.util.function.BiConsumer) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Matchers.contentEqualTo(io.servicetalk.buffer.api.Matchers.contentEqualTo) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nullable(javax.annotation.Nullable) CHUNKED(io.servicetalk.http.api.HttpHeaderValues.CHUNKED) SMALLEST_MAX_CONCURRENT_STREAMS(io.netty.handler.codec.http2.Http2CodecUtil.SMALLEST_MAX_CONCURRENT_STREAMS) DEFAULT(io.servicetalk.http.netty.HttpTestExecutionStrategy.DEFAULT) Single(io.servicetalk.concurrent.api.Single) StringWriter(java.io.StringWriter) Completable(io.servicetalk.concurrent.api.Completable) DefaultHttp2HeadersFrame(io.netty.handler.codec.http2.DefaultHttp2HeadersFrame) IOException(java.io.IOException) ReservedBlockingHttpConnection(io.servicetalk.http.api.ReservedBlockingHttpConnection) OK(io.servicetalk.http.api.HttpResponseStatus.OK) GET(io.servicetalk.http.api.HttpRequestMethod.GET) Channel(io.netty.channel.Channel) Http2Settings(io.netty.handler.codec.http2.Http2Settings) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) String.valueOf(java.lang.String.valueOf) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) HostAndPort(io.servicetalk.transport.api.HostAndPort) HttpRequestMethod(io.servicetalk.http.api.HttpRequestMethod) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Http2FrameCodecBuilder(io.netty.handler.codec.http2.Http2FrameCodecBuilder) Key.newKey(io.servicetalk.context.api.ContextMap.Key.newKey) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2DataFrame(io.netty.handler.codec.http2.Http2DataFrame) CONNECTION(io.servicetalk.http.api.HttpHeaderNames.CONNECTION) MethodSource(org.junit.jupiter.params.provider.MethodSource) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelInitializer(io.netty.channel.ChannelInitializer) PublisherSource(io.servicetalk.concurrent.PublisherSource) CONTENT_LENGTH(io.servicetalk.http.api.HttpHeaderNames.CONTENT_LENGTH) InetSocketAddress(java.net.InetSocketAddress) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) HttpEventKey(io.servicetalk.http.api.HttpEventKey) Test(org.junit.jupiter.api.Test) List(java.util.List) ContextMap(io.servicetalk.context.api.ContextMap) DelegatingConnectionAcceptor(io.servicetalk.transport.api.DelegatingConnectionAcceptor) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Writer(java.io.Writer) Queue(java.util.Queue) CONTINUE(io.servicetalk.http.api.HttpHeaderValues.CONTINUE) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Publisher(io.servicetalk.concurrent.api.Publisher) Http2Exception(io.servicetalk.http.api.Http2Exception) AtomicReference(java.util.concurrent.atomic.AtomicReference) StreamingHttpServiceFilter(io.servicetalk.http.api.StreamingHttpServiceFilter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpMetaData(io.servicetalk.http.api.HttpMetaData) HttpProtocolConfigs.h1Default(io.servicetalk.http.netty.HttpProtocolConfigs.h1Default) HttpProtocolConfigs.h2Default(io.servicetalk.http.netty.HttpProtocolConfigs.h2Default) HttpSerializers.textSerializerUtf8(io.servicetalk.http.api.HttpSerializers.textSerializerUtf8) HttpExecutionStrategy(io.servicetalk.http.api.HttpExecutionStrategy) NettyConnectionContext(io.servicetalk.transport.netty.internal.NettyConnectionContext) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) HttpServerBuilder(io.servicetalk.http.api.HttpServerBuilder) ConnectionContext(io.servicetalk.transport.api.ConnectionContext) KEEP_ALIVE(io.servicetalk.http.api.HttpHeaderValues.KEEP_ALIVE) INTERNAL_SERVER_ERROR(io.servicetalk.http.api.HttpResponseStatus.INTERNAL_SERVER_ERROR) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) EventLoopGroup(io.netty.channel.EventLoopGroup) ServerContext(io.servicetalk.transport.api.ServerContext) Iterator(java.util.Iterator) EXPECTATION_FAILED(io.servicetalk.http.api.HttpResponseStatus.EXPECTATION_FAILED) NettyIoExecutors.createIoExecutor(io.servicetalk.transport.netty.internal.NettyIoExecutors.createIoExecutor) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Processors.newPublisherProcessor(io.servicetalk.concurrent.api.Processors.newPublisherProcessor) Consumer(java.util.function.Consumer) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) PROXY_CONNECTION(io.servicetalk.http.netty.H2ToStH1Utils.PROXY_CONNECTION) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) NO_OFFLOAD(io.servicetalk.http.netty.HttpTestExecutionStrategy.NO_OFFLOAD) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelHandler(io.netty.channel.ChannelHandler) SET_COOKIE(io.servicetalk.http.api.HttpHeaderNames.SET_COOKIE) DefaultHttpCookiePair(io.servicetalk.http.api.DefaultHttpCookiePair) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) InetSocketAddress(java.net.InetSocketAddress) BuilderUtils.serverChannel(io.servicetalk.transport.netty.internal.BuilderUtils.serverChannel) Channel(io.netty.channel.Channel) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) ChannelInitializer(io.netty.channel.ChannelInitializer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 7 with OK

use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.

the class HttpAuthConnectionFactoryClientTest method simulateAuth.

@Test
void simulateAuth() throws Exception {
    serverContext = forAddress(localAddress(0)).ioExecutor(CTX.ioExecutor()).executionStrategy(offloadNone()).listenStreamingAndAwait((ctx, request, factory) -> succeeded(newTestResponse(factory)));
    client = forSingleAddress(serverHostAndPort(serverContext)).appendConnectionFactoryFilter(TestHttpAuthConnectionFactory::new).ioExecutor(CTX.ioExecutor()).executionStrategy(offloadNone()).buildStreaming();
    StreamingHttpResponse response = client.request(newTestRequest(client, "/foo")).toFuture().get();
    assertEquals(OK, response.status());
}
Also used : StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) HttpServers.forAddress(io.servicetalk.http.netty.HttpServers.forAddress) FilterableStreamingHttpConnection(io.servicetalk.http.api.FilterableStreamingHttpConnection) ZERO(io.servicetalk.http.api.HttpHeaderValues.ZERO) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) HttpExecutionStrategies.offloadNone(io.servicetalk.http.api.HttpExecutionStrategies.offloadNone) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DelegatingConnectionFactory(io.servicetalk.client.api.DelegatingConnectionFactory) Nullable(javax.annotation.Nullable) StreamingHttpRequestFactory(io.servicetalk.http.api.StreamingHttpRequestFactory) ConnectionFactory(io.servicetalk.client.api.ConnectionFactory) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) ExecutionContextExtension.immediate(io.servicetalk.transport.netty.internal.ExecutionContextExtension.immediate) ServerContext(io.servicetalk.transport.api.ServerContext) Single(io.servicetalk.concurrent.api.Single) HttpClients.forSingleAddress(io.servicetalk.http.netty.HttpClients.forSingleAddress) ExecutionContextExtension(io.servicetalk.transport.netty.internal.ExecutionContextExtension) CONTENT_LENGTH(io.servicetalk.http.api.HttpHeaderNames.CONTENT_LENGTH) OK(io.servicetalk.http.api.HttpResponseStatus.OK) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) ContextMap(io.servicetalk.context.api.ContextMap) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) TransportObserver(io.servicetalk.transport.api.TransportObserver) Single.failed(io.servicetalk.concurrent.api.Single.failed) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) Test(org.junit.jupiter.api.Test)

Example 8 with OK

use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.

the class HttpClientAsyncContextTest method makeClientRequestWithId.

private static void makeClientRequestWithId(StreamingHttpClient client, String requestId) throws ExecutionException, InterruptedException {
    StreamingHttpRequest request = client.get("/");
    request.headers().set(REQUEST_ID_HEADER, requestId);
    client.request(request).whenOnSuccess(response -> assertEquals(OK, response.status())).flatMapCompletable(response -> response.messageBody().ignoreElements()).toFuture().get();
}
Also used : FilterableStreamingHttpClient(io.servicetalk.http.api.FilterableStreamingHttpClient) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) StreamingHttpRequester(io.servicetalk.http.api.StreamingHttpRequester) CharSequences.newAsciiString(io.servicetalk.buffer.api.CharSequences.newAsciiString) Key.newKey(io.servicetalk.context.api.ContextMap.Key.newKey) Subscriber(io.servicetalk.concurrent.PublisherSource.Subscriber) AsyncContext(io.servicetalk.concurrent.api.AsyncContext) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HttpExecutionStrategies(io.servicetalk.http.api.HttpExecutionStrategies) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ValueSource(org.junit.jupiter.params.provider.ValueSource) AddressUtils.localAddress(io.servicetalk.transport.netty.internal.AddressUtils.localAddress) Matchers.empty(org.hamcrest.Matchers.empty) ServerContext(io.servicetalk.transport.api.ServerContext) Single(io.servicetalk.concurrent.api.Single) Subscription(io.servicetalk.concurrent.PublisherSource.Subscription) StreamingHttpClientFilter(io.servicetalk.http.api.StreamingHttpClientFilter) OK(io.servicetalk.http.api.HttpResponseStatus.OK) InetSocketAddress(java.net.InetSocketAddress) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ContextMap(io.servicetalk.context.api.ContextMap) Queue(java.util.Queue) HostAndPort(io.servicetalk.transport.api.HostAndPort) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest)

Example 9 with OK

use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.

the class RedirectingClientAndConnectionFilterTest method redirectFilterNoHostHeaderAbsoluteLocation.

@ParameterizedTest(name = "{displayName} [{index}] {0}-{1}")
@MethodSource("requesterTypes")
void redirectFilterNoHostHeaderAbsoluteLocation(final RequesterType type, final SecurityType security) throws Exception {
    setUp(security);
    BlockingHttpRequester client = asBlockingRequester(createFilter(type, (responseFactory, request) -> {
        if (request.requestTarget().equals("/")) {
            return succeeded(responseFactory.permanentRedirect().addHeader(LOCATION, format("http://%s/next", hostHeader(HostAndPort.of(remoteAddress())))));
        }
        return succeeded(responseFactory.ok());
    }, newFilterFactory()));
    HttpRequest request = client.get("/");
    HttpResponse response = client.request(request);
    assertThat(response.status(), equalTo(PERMANENT_REDIRECT));
    response = client.request(request.addHeader("X-REDIRECT", "TRUE"));
    assertThat(response.status(), equalTo(OK));
    // HTTP/1.0 doesn't support HOST => we can not infer that the absolute-form location is relative, don't redirect
    response = client.request(client.get("/").version(HTTP_1_0).addHeader("X-REDIRECT", "TRUE"));
    assertThat(response.status(), equalTo(PERMANENT_REDIRECT));
}
Also used : HttpConnection(io.servicetalk.http.api.HttpConnection) HttpResponse(io.servicetalk.http.api.HttpResponse) LOCATION(io.servicetalk.http.api.HttpHeaderNames.LOCATION) BlockingHttpRequester(io.servicetalk.http.api.BlockingHttpRequester) OK(io.servicetalk.http.api.HttpResponseStatus.OK) RedirectingHttpRequesterFilter(io.servicetalk.http.utils.RedirectingHttpRequesterFilter) String.format(java.lang.String.format) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FilterFactory(io.servicetalk.http.netty.ConditionalFilterFactory.FilterFactory) HttpRequest(io.servicetalk.http.api.HttpRequest) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HOST(io.servicetalk.http.api.HttpHeaderNames.HOST) PERMANENT_REDIRECT(io.servicetalk.http.api.HttpResponseStatus.PERMANENT_REDIRECT) AddressUtils.hostHeader(io.servicetalk.transport.netty.internal.AddressUtils.hostHeader) Matchers.equalTo(org.hamcrest.Matchers.equalTo) HttpClient(io.servicetalk.http.api.HttpClient) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HostHeaderHttpRequesterFilter(io.servicetalk.http.utils.HostHeaderHttpRequesterFilter) AbstractHttpRequesterFilterTest(io.servicetalk.http.api.AbstractHttpRequesterFilterTest) HostAndPort(io.servicetalk.transport.api.HostAndPort) MethodSource(org.junit.jupiter.params.provider.MethodSource) HTTP_1_0(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_0) HttpRequest(io.servicetalk.http.api.HttpRequest) HttpResponse(io.servicetalk.http.api.HttpResponse) BlockingHttpRequester(io.servicetalk.http.api.BlockingHttpRequester) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with OK

use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.

the class RedirectingClientAndConnectionFilterTest method redirectFilterNoHostHeaderRelativeLocation.

@ParameterizedTest(name = "{displayName} [{index}] {0}-{1}")
@MethodSource("requesterTypes")
void redirectFilterNoHostHeaderRelativeLocation(final RequesterType type, final SecurityType security) throws Exception {
    setUp(security);
    BlockingHttpRequester client = asBlockingRequester(createFilter(type, (responseFactory, request) -> {
        if (request.requestTarget().equals("/")) {
            return succeeded(responseFactory.permanentRedirect().addHeader(LOCATION, "/next"));
        }
        return succeeded(responseFactory.ok());
    }, newFilterFactory()));
    HttpRequest request = client.get("/");
    HttpResponse response = client.request(request);
    assertThat(response.status(), equalTo(PERMANENT_REDIRECT));
    response = client.request(request.addHeader("X-REDIRECT", "TRUE"));
    assertThat(response.status(), equalTo(OK));
    // HTTP/1.0 doesn't support HOST, ensure that we don't get any errors and perform relative redirect
    response = client.request(client.get("/").version(HTTP_1_0).addHeader("X-REDIRECT", "TRUE"));
    assertThat(response.status(), equalTo(OK));
}
Also used : HttpConnection(io.servicetalk.http.api.HttpConnection) HttpResponse(io.servicetalk.http.api.HttpResponse) LOCATION(io.servicetalk.http.api.HttpHeaderNames.LOCATION) BlockingHttpRequester(io.servicetalk.http.api.BlockingHttpRequester) OK(io.servicetalk.http.api.HttpResponseStatus.OK) RedirectingHttpRequesterFilter(io.servicetalk.http.utils.RedirectingHttpRequesterFilter) String.format(java.lang.String.format) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FilterFactory(io.servicetalk.http.netty.ConditionalFilterFactory.FilterFactory) HttpRequest(io.servicetalk.http.api.HttpRequest) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) HOST(io.servicetalk.http.api.HttpHeaderNames.HOST) PERMANENT_REDIRECT(io.servicetalk.http.api.HttpResponseStatus.PERMANENT_REDIRECT) AddressUtils.hostHeader(io.servicetalk.transport.netty.internal.AddressUtils.hostHeader) Matchers.equalTo(org.hamcrest.Matchers.equalTo) HttpClient(io.servicetalk.http.api.HttpClient) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HostHeaderHttpRequesterFilter(io.servicetalk.http.utils.HostHeaderHttpRequesterFilter) AbstractHttpRequesterFilterTest(io.servicetalk.http.api.AbstractHttpRequesterFilterTest) HostAndPort(io.servicetalk.transport.api.HostAndPort) MethodSource(org.junit.jupiter.params.provider.MethodSource) HTTP_1_0(io.servicetalk.http.api.HttpProtocolVersion.HTTP_1_0) HttpRequest(io.servicetalk.http.api.HttpRequest) HttpResponse(io.servicetalk.http.api.HttpResponse) BlockingHttpRequester(io.servicetalk.http.api.BlockingHttpRequester) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

OK (io.servicetalk.http.api.HttpResponseStatus.OK)21 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)17 HttpResponse (io.servicetalk.http.api.HttpResponse)13 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)12 ServerContext (io.servicetalk.transport.api.ServerContext)12 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)12 Test (org.junit.jupiter.api.Test)11 Single (io.servicetalk.concurrent.api.Single)10 HostAndPort (io.servicetalk.transport.api.HostAndPort)10 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)10 Matchers.is (org.hamcrest.Matchers.is)10 HttpRequest (io.servicetalk.http.api.HttpRequest)8 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)8 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)7 HttpExecutionStrategies.offloadNone (io.servicetalk.http.api.HttpExecutionStrategies.offloadNone)7 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 Nullable (javax.annotation.Nullable)7 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7