use of com.hotels.styx.client.netty.connectionpool.NettyConnectionFactory in project styx by ExpediaGroup.
the class StyxHttpClientTest method sendsToDefaultHttpPort.
/*
* StyxHttpClient.sendRequestInternal
* - Uses default HTTP port 8080 when not specified in Host header
*/
@Test
public void sendsToDefaultHttpPort() {
NettyConnectionFactory factory = mockConnectionFactory();
ArgumentCaptor<Origin> originCaptor = ArgumentCaptor.forClass(Origin.class);
StyxHttpClient.sendRequestInternal(factory, get("/").header(HOST, "localhost").build().stream(), new StyxHttpClient.Builder());
verify(factory).createConnection(originCaptor.capture(), any(ConnectionSettings.class), nullable(SslContext.class));
assertThat(originCaptor.getValue().port(), is(80));
}
use of com.hotels.styx.client.netty.connectionpool.NettyConnectionFactory in project styx by ExpediaGroup.
the class StyxHttpClientTest method mockConnectionFactory.
private static NettyConnectionFactory mockConnectionFactory() {
NettyConnectionFactory factory = mock(NettyConnectionFactory.class);
when(factory.createConnection(any(Origin.class), any(ConnectionSettings.class), nullable(SslContext.class))).thenReturn(Mono.just(mock(Connection.class)));
return factory;
}
use of com.hotels.styx.client.netty.connectionpool.NettyConnectionFactory in project styx by ExpediaGroup.
the class StyxHttpClientTest method sendsToDefaultHttpsPort.
/*
* StyxHttpClient.sendRequestInternal
* - Uses default HTTPS port 443 when not specified in Host header
*/
@Test
public void sendsToDefaultHttpsPort() {
NettyConnectionFactory factory = mockConnectionFactory();
ArgumentCaptor<Origin> originCaptor = ArgumentCaptor.forClass(Origin.class);
StyxHttpClient.sendRequestInternal(factory, get("/").header(HOST, "localhost").build().stream(), new StyxHttpClient.Builder().secure(true));
verify(factory).createConnection(originCaptor.capture(), any(ConnectionSettings.class), any(SslContext.class));
assertThat(originCaptor.getValue().port(), is(443));
}
use of com.hotels.styx.client.netty.connectionpool.NettyConnectionFactory in project styx by ExpediaGroup.
the class StyxHttpClient method sendRequestInternal.
// Visible for testing
static Mono<LiveHttpResponse> sendRequestInternal(NettyConnectionFactory connectionFactory, LiveHttpRequest request, Builder params) {
LiveHttpRequest networkRequest = addUserAgent(params.userAgent(), request);
Origin origin = originFromRequest(networkRequest, params.https());
SslContext sslContext = getSslContext(params.https(), params.tlsSettings());
return connectionFactory.createConnection(origin, new ConnectionSettings(params.connectTimeoutMillis()), sslContext).flatMap(connection -> Mono.from(connection.write(networkRequest).doOnComplete(connection::close).doOnError(e -> connection.close()).map(response -> response.newBuilder().body(it -> it.doOnEnd(x -> connection.close()).doOnCancel(() -> connection.close())).build())));
}
Aggregations