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);
}
}
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)));
}
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));
}
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);
}
}
}
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();
}
}
Aggregations