use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class EnforceSequentialModeRequesterFilter method request.
private static Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final StreamingHttpRequest request) {
return Single.defer(() -> {
CompletableSource.Processor requestSent = newCompletableProcessor();
StreamingHttpRequest r = request.transformMessageBody(messageBody -> messageBody.whenFinally(requestSent::onComplete));
return fromSource(requestSent).merge(delegate.request(r).toPublisher()).firstOrError().shareContextOnSubscribe();
});
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class GracefulConnectionClosureHandlingTest method closeAfterRequestMetaDataSentNoResponseReceived.
@ParameterizedTest(name = "{index}: protocol={0} initiateClosureFromClient={1} useUds={2} viaProxy={3}")
@MethodSource("data")
void closeAfterRequestMetaDataSentNoResponseReceived(HttpProtocol protocol, boolean initiateClosureFromClient, boolean useUds, boolean viaProxy) throws Exception {
setUp(protocol, initiateClosureFromClient, useUds, viaProxy);
CountDownLatch clientSendRequestPayload = new CountDownLatch(1);
StreamingHttpRequest request = newRequest("/first", clientSendRequestPayload);
Future<StreamingHttpResponse> responseFuture = connection.request(request).toFuture();
serverReceivedRequest.await();
triggerGracefulClosure();
serverSendResponse.countDown();
StreamingHttpResponse response = responseFuture.get();
assertResponse(response);
clientSendRequestPayload.countDown();
serverSendResponsePayload.countDown();
assertRequestPayloadBody(request);
assertResponsePayloadBody(response);
awaitConnectionClosed();
assertNextRequestFails();
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class GracefulConnectionClosureHandlingTest method closeAfterRequestMetaDataSentResponseMetaDataReceived.
@ParameterizedTest(name = "{index}: protocol={0} initiateClosureFromClient={1} useUds={2} viaProxy={3}")
@MethodSource("data")
void closeAfterRequestMetaDataSentResponseMetaDataReceived(HttpProtocol protocol, boolean initiateClosureFromClient, boolean useUds, boolean viaProxy) throws Exception {
setUp(protocol, initiateClosureFromClient, useUds, viaProxy);
CountDownLatch clientSendRequestPayload = new CountDownLatch(1);
StreamingHttpRequest request = newRequest("/first", clientSendRequestPayload);
Future<StreamingHttpResponse> responseFuture = connection.request(request).toFuture();
serverSendResponse.countDown();
StreamingHttpResponse response = responseFuture.get();
assertResponse(response);
triggerGracefulClosure();
clientSendRequestPayload.countDown();
serverSendResponsePayload.countDown();
assertRequestPayloadBody(request);
assertResponsePayloadBody(response);
awaitConnectionClosed();
assertNextRequestFails();
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method clientFilterAsyncContext.
@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void clientFilterAsyncContext(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
setUp(strategy, h2PriorKnowledge);
InetSocketAddress serverAddress = bindHttpEchoServer();
final Queue<Throwable> errorQueue = new ConcurrentLinkedQueue<>();
try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).appendClientFilter(client2 -> new StreamingHttpClientFilter(client2) {
@Override
protected Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final StreamingHttpRequest request) {
return asyncContextTestRequest(errorQueue, delegate, request);
}
}).buildBlocking()) {
final String responseBody = "foo";
HttpResponse response = client.request(client.post("/0").payloadBody(responseBody, textSerializerUtf8()));
assertEquals(responseBody, response.payloadBody(textSerializerUtf8()));
assertNoAsyncErrors(errorQueue);
}
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method clientSendsInvalidContentLength.
private void clientSendsInvalidContentLength(boolean addTrailers, BiConsumer<HttpHeaders, Integer> headersModifier) throws Exception {
assumeFalse(!h2PriorKnowledge && addTrailers, "HTTP/1.1 does not support Content-Length with trailers");
InetSocketAddress serverAddress = bindHttpEchoServer();
try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).appendClientFilter(client1 -> new StreamingHttpClientFilter(client1) {
@Override
protected Single<StreamingHttpResponse> request(final StreamingHttpRequester delegate, final StreamingHttpRequest request) {
return request.toRequest().map(req -> {
req.headers().remove(TRANSFER_ENCODING);
headersModifier.accept(req.headers(), req.payloadBody().readableBytes());
return req.toStreamingRequest();
}).flatMap(delegate::request);
}
}).buildBlocking()) {
HttpRequest request = client.get("/").payloadBody("a", textSerializerUtf8());
if (addTrailers) {
request.trailers().set("mytrailer", "myvalue");
}
if (h2PriorKnowledge) {
assertThrows(H2StreamResetException.class, () -> client.request(request));
} else {
try (ReservedBlockingHttpConnection reservedConn = client.reserveConnection(request)) {
assertThrows(IOException.class, () -> {
// Either the current request or the next one should fail
reservedConn.request(request);
reservedConn.request(client.get("/"));
});
}
}
}
}
Aggregations