use of io.servicetalk.buffer.api.BufferAllocator in project servicetalk by apple.
the class ExpectContinueTest method serverErrorAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverErrorAggregated(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);
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();
returnResponse.countDown();
HttpResponse response = responseFuture.get();
assertThat(response.status(), is(INTERNAL_SERVER_ERROR));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
// send a follow-up request on the same connection:
response = connection.request(connection.get("/")).toFuture().get();
assertThat(response.status(), is(OK));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
}
}
use of io.servicetalk.buffer.api.BufferAllocator in project servicetalk by apple.
the class ExpectContinueTest method serverRespondsWithSuccess.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverRespondsWithSuccess(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);
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));
returnResponse.countDown();
StreamingHttpResponse response = responses.take();
assertThat(response.status(), is(ACCEPTED));
sendRequestPayload(payload, allocator);
assertThat(response.toResponse().toFuture().get().payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
sendFollowUpRequest(connection, withCL, allocator, ACCEPTED);
}
}
use of io.servicetalk.buffer.api.BufferAllocator in project servicetalk by apple.
the class ContentCodingHttpRequesterFilter method codecTransformBidirectionalIfNeeded.
private Single<StreamingHttpResponse> codecTransformBidirectionalIfNeeded(final StreamingHttpRequester delegate, final StreamingHttpRequest request) {
final BufferAllocator alloc = delegate.executionContext().bufferAllocator();
setAcceptEncoding(request.headers(), acceptedEncodingsHeader);
encodePayloadContentIfAvailable(request, alloc);
return decodePayloadContentIfEncoded(delegate.request(request), alloc);
}
Aggregations