use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class ExpectContinueTest method retryExpectationFailedAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void retryExpectationFailedAggregated(HttpProtocol protocol, boolean withCL) throws Exception {
try (HttpServerContext serverContext = startServer(protocol);
HttpClient client = createClient(serverContext, protocol, new RetryingHttpRequesterFilter.Builder().retryExpectationFailed(true).build()).asClient()) {
Future<HttpResponse> responseFuture = client.request(newRequest(client, withCL, true, PAYLOAD + PAYLOAD, client.executionContext().bufferAllocator())).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));
}
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class ExpectContinueTest method expectationFailedAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void expectationFailedAggregated(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, true, PAYLOAD + PAYLOAD, allocator)).toFuture();
requestReceived.await();
sendContinue.countDown();
returnResponse.countDown();
HttpResponse response = responseFuture.get();
assertThat(response.status(), is(EXPECTATION_FAILED));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(""));
sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, OK);
}
}
use of io.servicetalk.http.api.HttpResponse 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);
}
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class ClientEmptyPayloadTest method firstRequestEmptyPayloadSecondRequestSucceeds.
@ParameterizedTest
@MethodSource("testArgs")
void firstRequestEmptyPayloadSecondRequestSucceeds(HttpRequestMethod method1, EncodingType type1, HttpRequestMethod method2, EncodingType type2) throws Exception {
try (ServerContext ctx = HttpServers.forAddress(localAddress(0)).listenBlockingAndAwait((ctx1, request, responseFactory) -> responseFactory.ok().payloadBody(request.payloadBody()));
BlockingHttpClient client = HttpClients.forResolvedAddress(serverHostAndPort(ctx)).buildBlocking()) {
HttpRequest req1 = client.newRequest(method1, "/");
setEncoding(req1.headers(), type1, 0);
HttpResponse resp1 = client.request(req1.payloadBody(client.executionContext().bufferAllocator().newBuffer()));
// Supply a non-empty payload if the method supports it.
String payload2 = method2 == HEAD || method2 == CONNECT || method2 == TRACE ? "" : "hello world2";
HttpRequest req2 = client.newRequest(method2, "/");
setEncoding(req2.headers(), type2, payload2.length());
HttpResponse resp2 = client.request(req2.payloadBody(client.executionContext().bufferAllocator().fromAscii(payload2)));
assertResponse(resp1, "");
assertResponse(resp2, payload2);
}
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class ConnectionFactoryFilterTest method sendRequest.
private static HttpResponse sendRequest(BlockingHttpClient client) throws Exception {
HttpResponse response = client.request(client.get("/"));
assertThat("Unexpected response.", response.status(), equalTo(HttpResponseStatus.OK));
return response;
}
Aggregations