use of io.servicetalk.http.api.StreamingHttpClient 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);
}
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class AbstractHttpServiceAsyncContextTest method contextPreservedOverFilterBoundaries.
final void contextPreservedOverFilterBoundaries(boolean useImmediate, boolean asyncFilter, boolean asyncService) throws Exception {
Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
try (ServerContext ctx = serverWithService(HttpServers.forAddress(localAddress(0)).appendServiceFilter(filterFactory(useImmediate, asyncFilter, errorQueue)), useImmediate, asyncService);
StreamingHttpClient client = HttpClients.forResolvedAddress(serverHostAndPort(ctx)).buildStreaming();
StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
makeClientRequestWithId(connection, "1");
assertThat("Error queue is not empty!", errorQueue, empty());
}
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class AbstractHttpServiceAsyncContextTest method connectionAcceptorContextDoesNotLeak.
final void connectionAcceptorContextDoesNotLeak(boolean serverUseImmediate) throws Exception {
try (ServerContext ctx = serverWithEmptyAsyncContextService(HttpServers.forAddress(localAddress(0)).appendConnectionAcceptorFilter(original -> new DelegatingConnectionAcceptor(context -> {
AsyncContext.put(K1, "v1");
return completed();
})), serverUseImmediate);
StreamingHttpClient client = HttpClients.forResolvedAddress(serverHostAndPort(ctx)).buildStreaming();
StreamingHttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get()) {
makeClientRequestWithId(connection, "1");
makeClientRequestWithId(connection, "2");
}
}
use of io.servicetalk.http.api.StreamingHttpClient 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, "");
}
}
use of io.servicetalk.http.api.StreamingHttpClient 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);
}
}
Aggregations