Search in sources :

Example 26 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 27 with HttpResponse

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

the class BasicAuthStrategyInfluencerTest method defaultOffloads.

@Test
void defaultOffloads() throws Exception {
    BlockingHttpClient client = setup(false);
    assert service != null;
    HttpResponse response = makeRequest(client);
    assertThat("Unexpected response.", response.status().code(), is(200));
    service.assertHandleOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
    service.assertRequestOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
    service.assertResponseOffload(not(startsWith(IO_EXECUTOR_NAME_PREFIX)));
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) HttpResponse(io.servicetalk.http.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 28 with HttpResponse

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

the class BlockingStreamingHttpServiceTest method doNotSendMetaData.

@Test
void doNotSendMetaData() throws Exception {
    BlockingStreamingHttpClient client = context((ctx, request, response) -> {
    // Noop
    });
    HttpClient asyncClient = client.asClient();
    final Future<HttpResponse> responseFuture = asyncClient.request(asyncClient.get("/")).toFuture();
    assertThrows(TimeoutException.class, () -> responseFuture.get(1, SECONDS));
}
Also used : BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) HttpClient(io.servicetalk.http.api.HttpClient) BlockingStreamingHttpClient(io.servicetalk.http.api.BlockingStreamingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) BlockingStreamingHttpResponse(io.servicetalk.http.api.BlockingStreamingHttpResponse) Test(org.junit.jupiter.api.Test)

Example 29 with HttpResponse

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

the class TracingHttpServiceFilterTest method testRequestWithTraceKeyWithNegativeSampledAndAlwaysTrueSampler.

@Test
void testRequestWithTraceKeyWithNegativeSampledAndAlwaysTrueSampler() throws Exception {
    final CountingInMemorySpanEventListener spanListener = new CountingInMemorySpanEventListener();
    try (ServerContext context = buildServer(spanListener, (__, ___) -> true)) {
        try (HttpClient client = forSingleAddress(serverHostAndPort(context)).build()) {
            String traceId = randomHexId();
            String spanId = randomHexId();
            String requestUrl = "/";
            HttpRequest request = client.get(requestUrl);
            request.headers().set(TRACE_ID, traceId).set(SPAN_ID, spanId).set(SAMPLED, "0");
            HttpResponse response = client.request(request).toFuture().get();
            TestSpanState serverSpanState = response.payloadBody(SPAN_STATE_SERIALIZER);
            assertSpan(spanListener, traceId, spanId, requestUrl, serverSpanState, true);
        }
    }
}
Also used : HttpRequest(io.servicetalk.http.api.HttpRequest) StreamingHttpRequest(io.servicetalk.http.api.StreamingHttpRequest) ServerContext(io.servicetalk.transport.api.ServerContext) HttpClient(io.servicetalk.http.api.HttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) CountingInMemorySpanEventListener(io.servicetalk.opentracing.http.TestUtils.CountingInMemorySpanEventListener) Test(org.junit.jupiter.api.Test)

Example 30 with HttpResponse

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

the class CompressionFilterExampleClient method main.

public static void main(String... args) throws Exception {
    try (HttpClient client = HttpClients.forSingleAddress("localhost", 8080).appendClientFilter(new ContentEncodingHttpRequesterFilter(new BufferDecoderGroupBuilder().add(deflateDefault(), true).add(identityEncoder(), false).build())).build()) {
        // Make a request with an uncompressed payload.
        HttpRequest request = client.post("/sayHello1").contentEncoding(identityEncoder()).payloadBody("World1", textSerializerUtf8());
        Single<HttpResponse> respSingle1 = client.request(request).whenOnSuccess(resp -> {
            System.out.println(resp.toString((name, value) -> value));
            System.out.println(resp.payloadBody(textSerializerUtf8()));
        });
        // Make a request with an gzip compressed payload.
        request = client.post("/sayHello2").contentEncoding(gzipDefault()).payloadBody("World2", textSerializerUtf8());
        Single<HttpResponse> respSingle2 = client.request(request).whenOnSuccess(resp -> {
            System.out.println(resp.toString((name, value) -> value));
            System.out.println(resp.payloadBody(textSerializerUtf8()));
        });
        // Issue the requests sequentially with concat.
        respSingle1.concat(respSingle2).toFuture().get();
    }
}
Also used : HttpRequest(io.servicetalk.http.api.HttpRequest) BufferDecoderGroupBuilder(io.servicetalk.encoding.api.BufferDecoderGroupBuilder) HttpRequest(io.servicetalk.http.api.HttpRequest) Single(io.servicetalk.concurrent.api.Single) HttpSerializers.textSerializerUtf8(io.servicetalk.http.api.HttpSerializers.textSerializerUtf8) HttpResponse(io.servicetalk.http.api.HttpResponse) NettyBufferEncoders.deflateDefault(io.servicetalk.encoding.netty.NettyBufferEncoders.deflateDefault) ContentEncodingHttpRequesterFilter(io.servicetalk.http.api.ContentEncodingHttpRequesterFilter) HttpClient(io.servicetalk.http.api.HttpClient) Identity.identityEncoder(io.servicetalk.encoding.api.Identity.identityEncoder) NettyBufferEncoders.gzipDefault(io.servicetalk.encoding.netty.NettyBufferEncoders.gzipDefault) HttpClients(io.servicetalk.http.netty.HttpClients) ContentEncodingHttpRequesterFilter(io.servicetalk.http.api.ContentEncodingHttpRequesterFilter) HttpClient(io.servicetalk.http.api.HttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) BufferDecoderGroupBuilder(io.servicetalk.encoding.api.BufferDecoderGroupBuilder)

Aggregations

HttpResponse (io.servicetalk.http.api.HttpResponse)95 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)53 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)42 ServerContext (io.servicetalk.transport.api.ServerContext)34 Test (org.junit.jupiter.api.Test)34 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)31 MethodSource (org.junit.jupiter.params.provider.MethodSource)26 HttpRequest (io.servicetalk.http.api.HttpRequest)25 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)25 HttpClient (io.servicetalk.http.api.HttpClient)23 HttpSerializers.textSerializerUtf8 (io.servicetalk.http.api.HttpSerializers.textSerializerUtf8)18 Single (io.servicetalk.concurrent.api.Single)17 OK (io.servicetalk.http.api.HttpResponseStatus.OK)17 InetSocketAddress (java.net.InetSocketAddress)16 StreamingHttpClient (io.servicetalk.http.api.StreamingHttpClient)15 AddressUtils.localAddress (io.servicetalk.transport.netty.internal.AddressUtils.localAddress)15 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)15 HttpClients (io.servicetalk.http.netty.HttpClients)14 Matchers.is (org.hamcrest.Matchers.is)14 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)13