use of io.servicetalk.http.netty.AbstractNettyHttpServerTest.ExecutorSupplier.CACHED in project servicetalk by apple.
the class ContentLengthAndTrailersTest method setUp.
private void setUp(HttpProtocol protocol, String content) {
this.protocol = protocol;
this.content = content;
protocol(protocol.config);
serviceFilterFactory(service -> new StreamingHttpServiceFilter(service) {
@Override
public Single<StreamingHttpResponse> handle(final HttpServiceContext ctx, final StreamingHttpRequest request, final StreamingHttpResponseFactory responseFactory) {
// Use transform to simulate access to request trailers
return delegate().handle(ctx, request.transform(new StatelessTrailersTransformer<>()), responseFactory).map(response -> {
final HttpHeaders headers = request.headers();
if (headers.contains(CONTENT_LENGTH)) {
response.setHeader(CLIENT_CONTENT_LENGTH, mergeValues(headers.values(CONTENT_LENGTH)));
}
if (headers.contains(TRANSFER_ENCODING)) {
response.setHeader(CLIENT_TRANSFER_ENCODING, mergeValues(headers.values(TRANSFER_ENCODING)));
}
return response;
});
}
});
setUp(CACHED, CACHED_SERVER);
}
use of io.servicetalk.http.netty.AbstractNettyHttpServerTest.ExecutorSupplier.CACHED in project servicetalk by apple.
the class RetryRequestWithNonRepeatablePayloadTest method setUp.
private void setUp(HttpProtocol protocol, TestPublisher<Buffer> payloadBody, Queue<Throwable> errors, boolean offloading) {
protocol(protocol.config);
ChannelOutboundHandler firstWriteHandler = new FailingFirstWriteHandler();
connectionFactoryFilter(ConnectionFactoryFilter.withStrategy(factory -> new DelegatingConnectionFactory<InetSocketAddress, FilterableStreamingHttpConnection>(factory) {
@Override
public Single<FilterableStreamingHttpConnection> newConnection(InetSocketAddress address, @Nullable TransportObserver observer) {
return delegate().newConnection(address, observer).map(c -> {
final Channel channel = ((NettyConnectionContext) c.connectionContext()).nettyChannel();
if (protocol == HTTP_1) {
// Insert right before HttpResponseDecoder to avoid seeing failed frames on wire logs
channel.pipeline().addBefore(HttpRequestEncoder.class.getSimpleName() + "#0", null, firstWriteHandler);
} else if (protocol == HTTP_2) {
// Insert right before Http2MultiplexHandler to avoid failing connection-level frames and
// seeing failed stream frames on frame/wire logs
channel.pipeline().addBefore(Http2MultiplexHandler.class.getSimpleName() + "#0", null, firstWriteHandler);
}
return new StreamingHttpConnectionFilter(c) {
@Override
public Single<StreamingHttpResponse> request(StreamingHttpRequest request) {
return delegate().request(request).whenOnError(t -> {
try {
assertThat("Unexpected exception type", t, instanceOf(RetryableException.class));
assertThat("Unexpected exception type", t.getCause(), instanceOf(DeliberateException.class));
assertThat("Unexpected subscribe to payload body", payloadBody.isSubscribed(), is(false));
} catch (Throwable error) {
errors.add(error);
}
});
}
};
});
}
}, ExecutionStrategy.offloadNone()));
setUp(offloading ? CACHED : IMMEDIATE, offloading ? CACHED_SERVER : IMMEDIATE);
}
use of io.servicetalk.http.netty.AbstractNettyHttpServerTest.ExecutorSupplier.CACHED in project servicetalk by apple.
the class RequestResponseContextTest method setUp.
void setUp(Api api) {
this.api = api;
connectionFilterFactory(connection -> new StreamingHttpConnectionFilter(connection) {
@Override
public Single<StreamingHttpResponse> request(StreamingHttpRequest request) {
final List<String> requestCtxValue = request.context().get(CLIENT_REQUEST_KEY);
try {
assertThat(requestCtxValue, is(notNullValue()));
assertThat(requestCtxValue, hasSize(1));
request.addHeader(CONTEXT_HEADER, requestCtxValue.get(0));
} catch (Throwable t) {
asyncError.add(t);
}
return delegate().request(request).map(response -> {
response.context().put(CLIENT_RESPONSE_KEY, valueOf(response.headers().get(CONTEXT_HEADER)));
return response;
});
}
});
serviceFilterFactory(service -> new StreamingHttpServiceFilter(service) {
@Override
public Single<StreamingHttpResponse> handle(HttpServiceContext ctx, StreamingHttpRequest request, StreamingHttpResponseFactory responseFactory) {
CharSequence requestCtxValue = request.headers().get(CONTEXT_HEADER);
try {
assertThat(requestCtxValue, is(notNullValue()));
request.context().put(SERVER_REQUEST_KEY, singletonList(requestCtxValue.toString()));
} catch (Throwable t) {
asyncError.add(t);
}
return delegate().handle(ctx, request, responseFactory).map(response -> {
response.headers().add(CONTEXT_HEADER, valueOf(response.context().get(SERVER_RESPONSE_KEY)));
return response;
});
}
});
setUp(CACHED, CACHED_SERVER);
}
Aggregations