Search in sources :

Example 1 with HttpServerContext

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

the class ExpectContinueTest method retryExpectationFailedAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void retryExpectationFailedAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol);
        HttpClient client = createClient(serverContext, protocol, new RetryingHttpRequesterFilter.Builder().retryExpectationFailed(true).build()).asClient()) {
        Future<HttpResponse> responseFuture = client.request(newRequest(client, withCL, true, PAYLOAD + PAYLOAD, client.executionContext().bufferAllocator())).toFuture();
        requestReceived.await();
        sendContinue.countDown();
        returnResponse.countDown();
        HttpResponse response = responseFuture.get();
        assertThat(response.status(), is(OK));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
    }
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpClient(io.servicetalk.http.api.HttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with HttpServerContext

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

the class ExpectContinueTest method serverRespondsWithRedirect.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverRespondsWithRedirect(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
        if ("/redirect".equals(request.requestTarget())) {
            response.status(PERMANENT_REDIRECT);
            response.setHeader(LOCATION, "/");
            response.sendMetaData().close();
            return;
        }
        requestReceived.countDown();
        sendContinue.await();
        StringBuilder sb = new StringBuilder();
        request.payloadBody().forEach(chunk -> sb.append(chunk.toString(US_ASCII)));
        returnResponse.await();
        try (HttpPayloadWriter<Buffer> writer = response.sendMetaData()) {
            writer.write(ctx.executionContext().bufferAllocator().fromAscii(sb));
        }
    });
        StreamingHttpClient client = createClient(serverContext, protocol, new RedirectingHttpRequesterFilter(new RedirectConfigBuilder().allowedMethods(POST).headersToRedirect(CONTENT_LENGTH, TRANSFER_ENCODING, EXPECT).redirectPayloadBody(true).build()));
        StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        TestPublisher<Buffer> payload = new TestPublisher.Builder<Buffer>().singleSubscriber().build();
        connection.request(newRequest(connection, withCL, false, payload).requestTarget("/redirect")).subscribe(responses::add);
        requestReceived.await();
        assertThat("Unexpected subscribe to payload body before 100 (Continue)", payload.isSubscribed(), is(false));
        sendContinue.countDown();
        sendRequestPayload(payload, allocator);
        returnResponse.countDown();
        assertResponse(OK, PAYLOAD + PAYLOAD);
        sendFollowUpRequest(connection, withCL, allocator, OK);
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) HttpServerContext(io.servicetalk.http.api.HttpServerContext) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) RedirectingHttpRequesterFilter(io.servicetalk.http.utils.RedirectingHttpRequesterFilter) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with HttpServerContext

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

the class ExpectContinueTest method expectationFailedAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectationFailedAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol);
        StreamingHttpClient client = createClient(serverContext, protocol);
        HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        Future<HttpResponse> responseFuture = connection.request(newRequest(connection, withCL, true, PAYLOAD + PAYLOAD, allocator)).toFuture();
        requestReceived.await();
        sendContinue.countDown();
        returnResponse.countDown();
        HttpResponse response = responseFuture.get();
        assertThat(response.status(), is(EXPECTATION_FAILED));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
        sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, OK);
    }
}
Also used : StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpConnection(io.servicetalk.http.api.HttpConnection) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with HttpServerContext

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

the class ExpectContinueTest method serverRespondsWithSuccessAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverRespondsWithSuccessAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
        requestReceived.countDown();
        returnResponse.await();
        response.status(ACCEPTED);
        try (HttpPayloadWriter<Buffer> writer = response.sendMetaData()) {
            for (Buffer chunk : request.payloadBody()) {
                writer.write(chunk);
            }
        }
    });
        StreamingHttpClient client = createClient(serverContext, protocol);
        HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
        BufferAllocator allocator = connection.executionContext().bufferAllocator();
        returnResponse.countDown();
        HttpResponse response = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture().get();
        assertThat(response.status(), is(ACCEPTED));
        assertThat(response.payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
        sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, ACCEPTED);
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) HttpConnection(io.servicetalk.http.api.HttpConnection) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) HttpServerContext(io.servicetalk.http.api.HttpServerContext) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with HttpServerContext

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

the class ExpectContinueTest method serverError.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverError(HttpProtocol protocol, boolean withCL) throws Exception {
    try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
        requestReceived.countDown();
        returnResponse.await();
        if (request.headers().contains(EXPECT, CONTINUE)) {
            response.status(INTERNAL_SERVER_ERROR);
        }
        response.sendMetaData().close();
    });
        StreamingHttpClient client = createClient(serverContext, protocol);
        StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
        TestPublisher<Buffer> payload = new TestPublisher.Builder<Buffer>().singleSubscriber().build();
        connection.request(newRequest(connection, withCL, true, payload)).subscribe(responses::add);
        requestReceived.await();
        assertThat("Unexpected subscribe to payload body before 100 (Continue)", payload.isSubscribed(), is(false));
        returnResponse.countDown();
        assertResponse(INTERNAL_SERVER_ERROR, "");
        // send a follow-up request on the same connection:
        connection.request(connection.get("/")).subscribe(responses::add);
        assertResponse(OK, "");
    }
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) StreamingHttpClient(io.servicetalk.http.api.StreamingHttpClient) RedirectConfigBuilder(io.servicetalk.http.api.RedirectConfigBuilder) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) HttpServerContext(io.servicetalk.http.api.HttpServerContext) StreamingHttpConnection(io.servicetalk.http.api.StreamingHttpConnection) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

HttpServerContext (io.servicetalk.http.api.HttpServerContext)16 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 MethodSource (org.junit.jupiter.params.provider.MethodSource)15 StreamingHttpConnection (io.servicetalk.http.api.StreamingHttpConnection)13 Buffer (io.servicetalk.buffer.api.Buffer)11 RedirectConfigBuilder (io.servicetalk.http.api.RedirectConfigBuilder)11 SingleAddressHttpClientBuilder (io.servicetalk.http.api.SingleAddressHttpClientBuilder)11 BufferAllocator (io.servicetalk.buffer.api.BufferAllocator)9 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)7 HttpResponse (io.servicetalk.http.api.HttpResponse)5 HttpConnection (io.servicetalk.http.api.HttpConnection)4 Channel (io.netty.channel.Channel)1 Single (io.servicetalk.concurrent.api.Single)1 Single.failed (io.servicetalk.concurrent.api.Single.failed)1 HttpClient (io.servicetalk.http.api.HttpClient)1 HttpExecutionContext (io.servicetalk.http.api.HttpExecutionContext)1 StreamingHttpService (io.servicetalk.http.api.StreamingHttpService)1 NoopChannelInitializer (io.servicetalk.http.netty.AlpnChannelSingle.NoopChannelInitializer)1 HTTP_1_1 (io.servicetalk.http.netty.AlpnIds.HTTP_1_1)1