use of io.servicetalk.http.api.HttpRequest in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method trailersWithContentLength.
@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void trailersWithContentLength(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
setUp(strategy, h2PriorKnowledge);
final String expectedPayload = "Hello World!";
final String expectedPayloadLength = valueOf(expectedPayload.length());
final String expectedTrailer = "foo";
final String expectedTrailerValue = "bar";
final AtomicReference<HttpRequest> requestReceived = new AtomicReference<>();
try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).listenBlockingAndAwait((ctx, request, responseFactory) -> {
requestReceived.set(request);
return responseFactory.ok().addTrailer(expectedTrailer, expectedTrailerValue).addHeader(CONTENT_LENGTH, expectedPayloadLength).payloadBody(expectedPayload, textSerializerUtf8());
});
BlockingHttpClient client = forSingleAddress(HostAndPort.of((InetSocketAddress) serverContext.listenAddress())).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildBlocking()) {
HttpResponse response = client.request(client.post("/").addTrailer(expectedTrailer, expectedTrailerValue).addHeader(CONTENT_LENGTH, expectedPayloadLength).payloadBody(expectedPayload, textSerializerUtf8()));
assertThat(response.status(), is(OK));
assertThat(response.payloadBody(textSerializerUtf8()), equalTo(expectedPayload));
assertHeaders(h2PriorKnowledge, response.headers(), expectedPayloadLength);
assertTrailers(response.trailers(), expectedTrailer, expectedTrailerValue);
// Verify what server received:
HttpRequest request = requestReceived.get();
assertThat(request.payloadBody(textSerializerUtf8()), equalTo(expectedPayload));
assertHeaders(h2PriorKnowledge, request.headers(), expectedPayloadLength);
assertTrailers(request.trailers(), expectedTrailer, expectedTrailerValue);
}
}
use of io.servicetalk.http.api.HttpRequest in project servicetalk by apple.
the class HostHeaderHttpRequesterFilterTest method assertResponse.
private void assertResponse(BlockingHttpRequester requester, @Nullable String hostHeader, String expectedValue) throws Exception {
final HttpRequest request = requester.get("/").version(httpVersionConfig.version());
if (hostHeader != null) {
request.setHeader(HOST, hostHeader);
}
HttpResponse response = requester.request(request);
assertThat(response.status(), equalTo(OK));
assertThat(response.version(), equalTo(httpVersionConfig.version()));
// "Host" header is not required for HTTP/1.0. Therefore, we may expect "null" here.
assertThat(response.payloadBody(textSerializerUtf8()), equalTo(httpVersionConfig == HttpVersionConfig.HTTP_1_0 && hostHeader == null ? "null" : expectedValue));
}
use of io.servicetalk.http.api.HttpRequest in project servicetalk by apple.
the class HttpClientOverrideOffloadingTest method reserveRespectsDisable.
@ParameterizedTest
@EnumSource(Params.class)
void reserveRespectsDisable(final Params params) throws Exception {
setUp(params);
ConcurrentLinkedQueue<AssertionError> errors = new ConcurrentLinkedQueue<>();
HttpRequest request = client.get("/");
request.context().put(HTTP_EXECUTION_STRATEGY_KEY, this.overridingStrategy);
client.reserveConnection(request).beforeOnSuccess(__ -> {
if (isInvalidThread()) {
errors.add(new AssertionError("Invalid thread found providing the connection. Thread: " + currentThread()));
}
}).toFuture().get().closeAsync().toFuture().get();
assertThat("Unexpected errors: " + errors, errors, hasSize(0));
}
use of io.servicetalk.http.api.HttpRequest in project servicetalk by apple.
the class HttpClientOverrideOffloadingTest method requestRespectsDisable.
@ParameterizedTest
@EnumSource(Params.class)
void requestRespectsDisable(final Params params) throws Exception {
setUp(params);
ConcurrentLinkedQueue<AssertionError> errors = new ConcurrentLinkedQueue<>();
HttpRequest request = client.get("/");
request.context().put(HTTP_EXECUTION_STRATEGY_KEY, this.overridingStrategy);
client.request(request).beforeOnSuccess(__ -> {
if (isInvalidThread()) {
errors.add(new AssertionError("Invalid thread called response. " + "Thread: " + currentThread()));
}
}).toFuture().get();
assertThat("Unexpected errors: " + errors, errors, hasSize(0));
}
use of io.servicetalk.http.api.HttpRequest in project servicetalk by apple.
the class AbstractBasicAuthSecurityContextFilterTest method getSecurityContextJson.
@Nullable
private String getSecurityContextJson(final String path, final boolean authenticated, final HttpResponseStatus expectedStatus) throws Exception {
final HttpRequest req = httpClient.get(path).appendPathSegments("security-context");
if (authenticated) {
req.setHeader(AUTHORIZATION, TEST_AUTHORIZATION);
}
final HttpResponse res = httpClient.request(req);
assertThat(res.status(), is(expectedStatus));
return OK.equals(res.status()) ? res.payloadBody().toString(UTF_8) : null;
}
Aggregations