use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class ExpectContinueTest method expectationFailed.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectationFailed(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol);
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(EXPECTATION_FAILED, "");
assertThat("Unexpected subscribe to payload body on expectation failed", payload.isSubscribed(), is(false));
sendContinue.countDown();
sendFollowUpRequest(connection, withCL, connection.executionContext().bufferAllocator(), OK);
}
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class ExpectContinueTest method expectContinue.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinue(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol);
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(OK, PAYLOAD + PAYLOAD);
sendFollowUpRequest(connection, withCL, allocator, OK);
}
}
use of io.servicetalk.http.api.StreamingHttpConnection in project servicetalk by apple.
the class ExpectContinueTest method expectContinueConnectionClose.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectContinueConnectionClose(HttpProtocol protocol, boolean withCL) throws Exception {
assumeTrue(protocol == HTTP_1);
try (HttpServerContext serverContext = startServer(protocol);
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, false, payload).setHeader(CONNECTION, CLOSE)).subscribe(responses::add);
requestReceived.await();
assertThat("Unexpected subscribe to payload body before 100 (Continue)", payload.isSubscribed(), is(false));
sendContinue.countDown();
sendRequestPayload(payload, connection.executionContext().bufferAllocator());
returnResponse.countDown();
assertResponse(OK, PAYLOAD + PAYLOAD);
connection.onClose().toFuture().get();
}
}
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();
}
Aggregations