use of io.servicetalk.http.api.StreamingHttpConnection 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.StreamingHttpConnection in project servicetalk by apple.
the class ExpectContinueTest method expectContinueThenFailure.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinueThenFailure(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol, (ctx, request, response) -> {
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.status(UNPROCESSABLE_ENTITY).sendMetaData()) {
writer.write(ctx.executionContext().bufferAllocator().fromAscii(sb));
}
});
StreamingHttpClient client = createClient(serverContext, protocol);
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)).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(UNPROCESSABLE_ENTITY, PAYLOAD + PAYLOAD);
sendFollowUpRequest(connection, withCL, allocator, UNPROCESSABLE_ENTITY);
}
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class FlushStrategyForClientApiTest method streamingApiShouldFlushOnEach.
@Test
void streamingApiShouldFlushOnEach() throws Exception {
final StreamingHttpConnection connection = streamingHttpConnection();
final SingleSource.Processor<Buffer, Buffer> payloadItemProcessor = Processors.newSingleProcessor();
final Publisher<Buffer> payload = fromSource(payloadItemProcessor).toPublisher();
final Single<StreamingHttpResponse> responseSingle = connection.request(connection.newRequest(POST, "/").payloadBody(payload));
// Subscribe, to initiate the request, but we don't care about the response.
responseSingle.toFuture();
// Wait for the server to receive the response, meaning the client wrote and flushed.
requestLatch.await();
MatcherAssert.assertThat(payloadBuffersReceived.size(), is(0));
final Buffer payloadItem = BufferAllocators.DEFAULT_ALLOCATOR.fromAscii("Hello");
payloadItemProcessor.onSuccess(payloadItem);
// Wait for the server to receive the payload
Buffer receivedBuffer = payloadBuffersReceived.take();
MatcherAssert.assertThat(receivedBuffer, is(payloadItem));
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class FlushStrategyForClientApiTest method aggregatedApiShouldNotOverrideExplicit.
@Test
void aggregatedApiShouldNotOverrideExplicit() throws Exception {
final StreamingHttpConnection connection = streamingHttpConnection();
((NettyConnectionContext) connection.connectionContext()).updateFlushStrategy((prev, isOriginal) -> FlushStrategies.flushOnEach());
final Single<StreamingHttpResponse> responseSingle = connection.request(connection.asConnection().newRequest(POST, "/").addHeader(TRANSFER_ENCODING, CHUNKED).toStreamingRequest().payloadBody(Publisher.never()));
// Subscribe, to initiate the request, but we don't care about the response.
responseSingle.toFuture();
// Wait for the server to receive the response, meaning the client wrote and flushed.
requestLatch.await();
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class FullDuplexAndSequentialModeTest method deferResponseUntilAfterRequestSent.
@Test
void deferResponseUntilAfterRequestSent() throws Exception {
clientFilterFactory(EnforceSequentialModeRequesterFilter.INSTANCE);
setUp(CACHED, CACHED_SERVER);
StreamingHttpConnection connection = streamingHttpConnection();
CountDownLatch continueRequest = new CountDownLatch(1);
try (InputStream payload = payload()) {
Future<StreamingHttpResponse> responseFuture = stallingSendRequest(connection, continueRequest, payload);
// Delay completion of the request payload body:
Thread.sleep(100);
// response meta-data completes only after request is sent
assertThat(responseFuture.isDone(), is(false));
continueRequest.countDown();
assertResponse(responseFuture.get(), HTTP_1_1, OK, SIZE);
}
}
Aggregations