use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.
the class PartitionedHttpClientTest method testPartitionByHeader.
@Test
void testPartitionByHeader() throws Exception {
final Function<HttpRequestMetaData, PartitionAttributesBuilder> selector = req -> new DefaultPartitionAttributesBuilder(1).add(SRV_NAME, requireNonNull(req.headers().get(X_SERVER)).toString());
try (BlockingHttpClient clt = HttpClients.forPartitionedAddress(psd, "test-cluster", selector).initializer((pa, builder) -> builder.unresolvedAddressToHost(addr -> pa.get(SRV_NAME))).buildBlocking()) {
sdPublisher.onSubscribe(new TestSubscription());
sdPublisher.onNext(new TestPSDE(SRV_1, (InetSocketAddress) srv1.listenAddress()), new TestPSDE(SRV_2, (InetSocketAddress) srv2.listenAddress()));
final HttpResponse httpResponse1 = clt.request(clt.get("/").addHeader(X_SERVER, SRV_2));
final HttpResponse httpResponse2 = clt.request(clt.get("/").addHeader(X_SERVER, SRV_1));
MatcherAssert.assertThat(httpResponse1.headers().get(X_SERVER), hasToString(SRV_2));
MatcherAssert.assertThat(httpResponse2.headers().get(X_SERVER), hasToString(SRV_1));
}
}
use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.
the class PartitionedHttpClientTest method testPartitionByLeader.
@Test
void testPartitionByLeader() throws Exception {
final Function<HttpRequestMetaData, PartitionAttributesBuilder> selector = req -> new DefaultPartitionAttributesBuilder(1).add(SRV_LEADER, true);
try (BlockingHttpClient clt = HttpClients.forPartitionedAddress(psd, "test-cluster", selector).buildBlocking()) {
sdPublisher.onSubscribe(new TestSubscription());
sdPublisher.onNext(new TestPSDE(SRV_1, false, (InetSocketAddress) srv1.listenAddress()), new TestPSDE(SRV_2, true, (InetSocketAddress) srv2.listenAddress()));
final HttpResponse httpResponse1 = clt.request(clt.get("/foo"));
final HttpResponse httpResponse2 = clt.request(clt.get("/bar"));
MatcherAssert.assertThat(httpResponse1.headers().get(X_SERVER), hasToString(SRV_2));
MatcherAssert.assertThat(httpResponse2.headers().get(X_SERVER), hasToString(SRV_2));
}
}
use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.
the class HttpRequestDecoderTest method assertRequestLine.
private static HttpRequestMetaData assertRequestLine(HttpRequestMethod expectedMethod, String expectedRequestTarget, HttpProtocolVersion expectedVersion, EmbeddedChannel channel) {
HttpRequestMetaData request = channel.readInbound();
assertThat(request.method(), equalTo(expectedMethod));
assertThat(request.requestTarget(), equalTo(expectedRequestTarget));
assertThat(request.version(), equalTo(expectedVersion));
return request;
}
use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.
the class HttpRequestEncoderTest method variableNoTrailersNoContent.
@Test
void variableNoTrailersNoContent() {
EmbeddedChannel channel = newEmbeddedChannel();
HttpRequestMetaData request = newRequestMetaData(HTTP_1_1, GET, "/some/path?foo=bar&baz=yyy", INSTANCE.newHeaders());
request.headers().add(CONNECTION, KEEP_ALIVE).add(USER_AGENT, "unit-test");
channel.writeOutbound(request);
channel.writeOutbound(EMPTY_BUFFER);
channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
verifyHttpRequest(channel, EMPTY_BUFFER, TransferEncoding.Variable, false);
assertFalse(channel.finishAndReleaseAll());
}
use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.
the class HttpRequestEncoderTest method withContentLengthAndChunked.
@Test
void withContentLengthAndChunked() {
EmbeddedChannel channel = newEmbeddedChannel();
byte[] content = new byte[128];
ThreadLocalRandom.current().nextBytes(content);
Buffer buffer = allocator.wrap(content);
HttpRequestMetaData request = newRequestMetaData(HTTP_1_1, GET, "/some/path?foo=bar&baz=yyy", INSTANCE.newHeaders());
request.headers().add(CONNECTION, KEEP_ALIVE).add(USER_AGENT, "unit-test").add(CONTENT_LENGTH, valueOf(content.length)).add(TRANSFER_ENCODING, CHUNKED);
channel.writeOutbound(request);
channel.writeOutbound(buffer.duplicate());
channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
String metaData = verifyHttpRequest(channel, buffer, TransferEncoding.Chunked, false);
assertFalse(metaData.contains(CONTENT_LENGTH), "Unexpected content-length header in meta-data while chunked encoding is used: " + metaData);
assertFalse(channel.finishAndReleaseAll());
}
Aggregations