Search in sources :

Example 11 with HttpResponse

use of io.servicetalk.http.api.HttpResponse 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 12 with HttpResponse

use of io.servicetalk.http.api.HttpResponse 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 13 with HttpResponse

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

the class ExpectContinueTest method expectContinueAggregated.

@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinueAggregated(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, false, PAYLOAD + PAYLOAD, allocator)).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));
        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 14 with HttpResponse

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

the class ClientEmptyPayloadTest method firstRequestEmptyPayloadSecondRequestSucceeds.

@ParameterizedTest
@MethodSource("testArgs")
void firstRequestEmptyPayloadSecondRequestSucceeds(HttpRequestMethod method1, EncodingType type1, HttpRequestMethod method2, EncodingType type2) throws Exception {
    try (ServerContext ctx = HttpServers.forAddress(localAddress(0)).listenBlockingAndAwait((ctx1, request, responseFactory) -> responseFactory.ok().payloadBody(request.payloadBody()));
        BlockingHttpClient client = HttpClients.forResolvedAddress(serverHostAndPort(ctx)).buildBlocking()) {
        HttpRequest req1 = client.newRequest(method1, "/");
        setEncoding(req1.headers(), type1, 0);
        HttpResponse resp1 = client.request(req1.payloadBody(client.executionContext().bufferAllocator().newBuffer()));
        // Supply a non-empty payload if the method supports it.
        String payload2 = method2 == HEAD || method2 == CONNECT || method2 == TRACE ? "" : "hello world2";
        HttpRequest req2 = client.newRequest(method2, "/");
        setEncoding(req2.headers(), type2, payload2.length());
        HttpResponse resp2 = client.request(req2.payloadBody(client.executionContext().bufferAllocator().fromAscii(payload2)));
        assertResponse(resp1, "");
        assertResponse(resp2, payload2);
    }
}
Also used : HttpRequest(io.servicetalk.http.api.HttpRequest) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with HttpResponse

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

the class ConnectionFactoryFilterTest method sendRequest.

private static HttpResponse sendRequest(BlockingHttpClient client) throws Exception {
    HttpResponse response = client.request(client.get("/"));
    assertThat("Unexpected response.", response.status(), equalTo(HttpResponseStatus.OK));
    return response;
}
Also used : StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) HttpResponse(io.servicetalk.http.api.HttpResponse)

Aggregations

HttpResponse (io.servicetalk.http.api.HttpResponse)107 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)65 Test (org.junit.jupiter.api.Test)46 ServerContext (io.servicetalk.transport.api.ServerContext)45 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)44 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)35 HttpRequest (io.servicetalk.http.api.HttpRequest)29 MethodSource (org.junit.jupiter.params.provider.MethodSource)29 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)26 HttpClient (io.servicetalk.http.api.HttpClient)23 InetSocketAddress (java.net.InetSocketAddress)22 OK (io.servicetalk.http.api.HttpResponseStatus.OK)21 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)21 Single (io.servicetalk.concurrent.api.Single)19 HttpSerializers.textSerializerUtf8 (io.servicetalk.http.api.HttpSerializers.textSerializerUtf8)19 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)19 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)19 Matchers.is (org.hamcrest.Matchers.is)18 HostAndPort (io.servicetalk.transport.api.HostAndPort)17 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)16