use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class RedirectingClientAndConnectionFilterTest method redirectFilterNoHostHeaderRelativeLocation.
@ParameterizedTest(name = "{displayName} [{index}] {0}-{1}")
@MethodSource("requesterTypes")
void redirectFilterNoHostHeaderRelativeLocation(final RequesterType type, final SecurityType security) throws Exception {
setUp(security);
BlockingHttpRequester client = asBlockingRequester(createFilter(type, (responseFactory, request) -> {
if (request.requestTarget().equals("/")) {
return succeeded(responseFactory.permanentRedirect().addHeader(LOCATION, "/next"));
}
return succeeded(responseFactory.ok());
}, newFilterFactory()));
HttpRequest request = client.get("/");
HttpResponse response = client.request(request);
assertThat(response.status(), equalTo(PERMANENT_REDIRECT));
response = client.request(request.addHeader("X-REDIRECT", "TRUE"));
assertThat(response.status(), equalTo(OK));
// HTTP/1.0 doesn't support HOST, ensure that we don't get any errors and perform relative redirect
response = client.request(client.get("/").version(HTTP_1_0).addHeader("X-REDIRECT", "TRUE"));
assertThat(response.status(), equalTo(OK));
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class NettyHttpServerConnectionDrainTest method postLargePayloadAndAssertResponseOk.
private static void postLargePayloadAndAssertResponseOk(final BlockingHttpClient client) throws Exception {
HttpResponse response = client.request(client.post("/").payloadBody(LARGE_TEXT, textSerializerUtf8()));
assertThat(response.toStreamingResponse().payloadBody(appSerializerUtf8FixLen()).collect(StringBuilder::new, StringBuilder::append).toFuture().get().toString(), equalTo("OK"));
}
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 serverRespondsWithSuccessAggregated.
@ParameterizedTest(name = "protocol={0} withCL={1}")
@MethodSource("arguments")
void serverRespondsWithSuccessAggregated(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);
HttpConnection connection = client.reserveConnection(client.get("/")).toFuture().get().asConnection()) {
BufferAllocator allocator = connection.executionContext().bufferAllocator();
returnResponse.countDown();
HttpResponse response = connection.request(newRequest(connection, withCL, false, PAYLOAD + PAYLOAD, allocator)).toFuture().get();
assertThat(response.status(), is(ACCEPTED));
assertThat(response.payloadBody().toString(US_ASCII), equalTo(PAYLOAD + PAYLOAD));
sendFollowUpRequest(connection.asStreamingConnection(), withCL, allocator, ACCEPTED);
}
}
Aggregations