use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class HttpServerMultipleRequestsTest method makeClientRequestWithId.
private static void makeClientRequestWithId(StreamingHttpConnection connection, String requestId) throws ExecutionException, InterruptedException {
StreamingHttpRequest request = connection.get("/");
request.headers().set(REQUEST_ID_HEADER, requestId);
StreamingHttpResponse response = connection.request(request).toFuture().get();
assertEquals(OK, response.status());
assertTrue(request.headers().contains(REQUEST_ID_HEADER, requestId));
response.messageBody().ignoreElements().subscribe();
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class HttpStreamingClientOverrideOffloadingTest method reserveRespectsDisable.
@ParameterizedTest
@EnumSource(Params.class)
void reserveRespectsDisable(final Params params) throws Exception {
setUp(params);
StreamingHttpRequest request = client.get("/");
request.context().put(HTTP_EXECUTION_STRATEGY_KEY, this.overridingStrategy);
client.reserveConnection(request).beforeOnSuccess(__ -> {
if (isInvalidThread()) {
throw new AssertionError("Invalid thread found providing the connection. Thread: " + currentThread());
}
}).toFuture().get().closeAsync().toFuture().get();
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class HttpTransportObserverTest method setUp.
private void setUp(HttpProtocol protocol) {
this.protocol = protocol;
protocol(protocol.config);
connectionAcceptor(ctx -> {
ctx.onClose().whenFinally(serverConnectionClosed::countDown).subscribe();
return completed();
});
serviceFilterFactory(service -> new StreamingHttpServiceFilter(service) {
@Override
public Single<StreamingHttpResponse> handle(HttpServiceContext ctx, StreamingHttpRequest request, StreamingHttpResponseFactory responseFactory) {
requestReceived.countDown();
try {
processRequest.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throwException(e);
}
return delegate().handle(ctx, request, responseFactory);
}
});
clientTransportObserver = mock(TransportObserver.class, "clientTransportObserver");
clientConnectionObserver = mock(ConnectionObserver.class, "clientConnectionObserver");
clientDataObserver = mock(DataObserver.class, "clientDataObserver");
clientMultiplexedObserver = mock(MultiplexedObserver.class, "clientMultiplexedObserver");
clientStreamObserver = mock(StreamObserver.class, "clientStreamObserver");
clientReadObserver = mock(ReadObserver.class, "clientReadObserver");
clientWriteObserver = mock(WriteObserver.class, "clientWriteObserver");
when(clientTransportObserver.onNewConnection(any(), any())).thenReturn(clientConnectionObserver);
lenient().when(clientConnectionObserver.connectionEstablished(any(ConnectionInfo.class))).thenReturn(clientDataObserver);
lenient().when(clientConnectionObserver.multiplexedConnectionEstablished(any(ConnectionInfo.class))).thenReturn(clientMultiplexedObserver);
lenient().when(clientMultiplexedObserver.onNewStream()).thenReturn(clientStreamObserver);
lenient().when(clientStreamObserver.streamEstablished()).thenReturn(clientDataObserver);
lenient().when(clientDataObserver.onNewRead()).thenReturn(clientReadObserver);
lenient().when(clientDataObserver.onNewWrite()).thenReturn(clientWriteObserver);
serverTransportObserver = mock(TransportObserver.class, "serverTransportObserver");
serverConnectionObserver = mock(ConnectionObserver.class, "serverConnectionObserver");
serverDataObserver = mock(DataObserver.class, "serverDataObserver");
serverMultiplexedObserver = mock(MultiplexedObserver.class, "serverMultiplexedObserver");
serverStreamObserver = mock(StreamObserver.class, "serverStreamObserver");
serverReadObserver = mock(ReadObserver.class, "serverReadObserver");
serverWriteObserver = mock(WriteObserver.class, "serverWriteObserver");
when(serverTransportObserver.onNewConnection(any(), any())).thenReturn(serverConnectionObserver);
lenient().when(serverConnectionObserver.connectionEstablished(any(ConnectionInfo.class))).thenReturn(serverDataObserver);
lenient().when(serverConnectionObserver.multiplexedConnectionEstablished(any(ConnectionInfo.class))).thenReturn(serverMultiplexedObserver);
lenient().when(serverMultiplexedObserver.onNewStream()).thenReturn(serverStreamObserver);
lenient().when(serverStreamObserver.streamEstablished()).thenReturn(serverDataObserver);
lenient().when(serverDataObserver.onNewRead()).thenReturn(serverReadObserver);
lenient().when(serverDataObserver.onNewWrite()).thenReturn(serverWriteObserver);
transportObserver(clientTransportObserver, serverTransportObserver);
setUp(CACHED, CACHED_SERVER);
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class MalformedDataAfterHttpMessageTest method afterResponseNextClientRequestSucceeds.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void afterResponseNextClientRequestSucceeds(boolean doOffloading) throws Exception {
Queue<ConnectionContext> contextQueue = new LinkedBlockingQueue<>();
ServerSocketChannel server = nettyServer(RESPONSE_MSG);
try (BlockingHttpClient client = stClientBuilder(server.localAddress()).executionStrategy(doOffloading ? defaultStrategy() : offloadNone()).appendClientFilter(new RetryingHttpRequesterFilter.Builder().retryOther((req, cause) -> ofConstantBackoffFullJitter(ofNanos(1), MAX_VALUE)).build()).appendConnectionFilter(connection -> new StreamingHttpConnectionFilter(connection) {
@Override
public Single<StreamingHttpResponse> request(final StreamingHttpRequest request) {
contextQueue.add(connectionContext());
return super.request(request);
}
}).buildBlocking()) {
validateClientResponse(client.request(client.get("/1")));
validateClientResponse(client.request(client.get("/2")));
ConnectionContext ctx1 = contextQueue.poll();
assertThat(ctx1, not(nullValue()));
// RetryingHttpRequesterFilter or AutoRetry may re-issue the request if a failure is seen locally. Verify
// the last connection (used for second request) is different from the first.
ConnectionContext ctx2 = null;
ConnectionContext tmp;
while ((tmp = contextQueue.poll()) != null) {
ctx2 = tmp;
}
assertThat(ctx2, not(nullValue()));
assertThat(ctx1, not(equalTo(ctx2)));
assertThat(contextQueue, empty());
} finally {
server.close().sync();
}
}
use of io.servicetalk.http.api.StreamingHttpRequest in project servicetalk by apple.
the class MultiAddressUrlHttpClientTest method requestWithRelativeFormRequestTarget.
@Test
void requestWithRelativeFormRequestTarget() {
StreamingHttpRequest request = client.get("/200?param=value");
// no host header
toSource(client.request(request)).subscribe(subscriber);
assertThat(subscriber.awaitOnError(), is(instanceOf(MalformedURLException.class)));
}
Aggregations