use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method h2LayerFiltersOutProhibitedH1HeadersOnClientSide.
@Test
void h2LayerFiltersOutProhibitedH1HeadersOnClientSide() throws Exception {
setUp(DEFAULT, true);
serverAcceptorChannel = bindH2Server(serverEventLoopGroup, new ChannelInitializer<Channel>() {
@Override
protected void initChannel(final Channel ch) {
ch.pipeline().addLast(new EchoHttp2Handler());
}
}, __ -> {
}, identity());
InetSocketAddress serverAddress = (InetSocketAddress) serverAcceptorChannel.localAddress();
try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(HttpProtocol.HTTP_2.config).enableWireLogging("servicetalk-tests-wire-logger", LogLevel.TRACE, () -> true).executionStrategy(clientExecutionStrategy).buildBlocking()) {
HttpResponse response = client.request(addProhibitedHeaders(client.post("/")).payloadBody(client.executionContext().bufferAllocator().fromAscii("content")));
assertThat(response.status(), is(OK));
}
}
use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.
the class HttpAuthConnectionFactoryClientTest method simulateAuth.
@Test
void simulateAuth() throws Exception {
serverContext = forAddress(localAddress(0)).ioExecutor(CTX.ioExecutor()).executionStrategy(offloadNone()).listenStreamingAndAwait((ctx, request, factory) -> succeeded(newTestResponse(factory)));
client = forSingleAddress(serverHostAndPort(serverContext)).appendConnectionFactoryFilter(TestHttpAuthConnectionFactory::new).ioExecutor(CTX.ioExecutor()).executionStrategy(offloadNone()).buildStreaming();
StreamingHttpResponse response = client.request(newTestRequest(client, "/foo")).toFuture().get();
assertEquals(OK, response.status());
}
use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.
the class HttpClientAsyncContextTest method makeClientRequestWithId.
private static void makeClientRequestWithId(StreamingHttpClient client, String requestId) throws ExecutionException, InterruptedException {
StreamingHttpRequest request = client.get("/");
request.headers().set(REQUEST_ID_HEADER, requestId);
client.request(request).whenOnSuccess(response -> assertEquals(OK, response.status())).flatMapCompletable(response -> response.messageBody().ignoreElements()).toFuture().get();
}
use of io.servicetalk.http.api.HttpResponseStatus.OK in project servicetalk by apple.
the class RedirectingClientAndConnectionFilterTest method redirectFilterNoHostHeaderAbsoluteLocation.
@ParameterizedTest(name = "{displayName} [{index}] {0}-{1}")
@MethodSource("requesterTypes")
void redirectFilterNoHostHeaderAbsoluteLocation(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, format("http://%s/next", hostHeader(HostAndPort.of(remoteAddress())))));
}
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 => we can not infer that the absolute-form location is relative, don't redirect
response = client.request(client.get("/").version(HTTP_1_0).addHeader("X-REDIRECT", "TRUE"));
assertThat(response.status(), equalTo(PERMANENT_REDIRECT));
}
use of io.servicetalk.http.api.HttpResponseStatus.OK 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));
}
Aggregations