Search in sources :

Example 1 with HttpRequestMetaData

use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.

the class HttpRequestEncoderTest method contentLengthNoTrailers.

@Test
void contentLengthNoTrailers() {
    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));
    channel.writeOutbound(request);
    channel.writeOutbound(buffer.duplicate());
    channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
    verifyHttpRequest(channel, buffer, TransferEncoding.ContentLength, false);
    consumeEmptyBufferFromTrailers(channel);
    assertFalse(channel.finishAndReleaseAll());
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with HttpRequestMetaData

use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.

the class HttpRequestEncoderTest method contentLengthNoTrailersHeaderWhiteSpaceThrowByDefault.

@Test
void contentLengthNoTrailersHeaderWhiteSpaceThrowByDefault() {
    EmbeddedChannel channel = newEmbeddedChannel();
    HttpRequestMetaData request = newRequestMetaData(HTTP_1_1, GET, "/some/path?foo=bar&baz=yyy", INSTANCE.newHeaders());
    assertThrows(IllegalArgumentException.class, () -> request.addHeader(" " + CONNECTION, KEEP_ALIVE));
    assertFalse(channel.finishAndReleaseAll());
}
Also used : HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with HttpRequestMetaData

use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.

the class HttpRequestEncoderTest method chunkedNoTrailersNoContent.

@Test
void chunkedNoTrailersNoContent() {
    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").add(TRANSFER_ENCODING, CHUNKED);
    channel.writeOutbound(request);
    channel.writeOutbound(EMPTY_BUFFER.duplicate());
    channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
    verifyHttpRequest(channel, EMPTY_BUFFER, TransferEncoding.Chunked, false);
    assertFalse(channel.finishAndReleaseAll());
}
Also used : HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with HttpRequestMetaData

use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.

the class HttpRequestEncoderTest method chunkedWithTrailers.

@Test
void chunkedWithTrailers() {
    EmbeddedChannel channel = newEmbeddedChannel();
    byte[] content = new byte[128];
    ThreadLocalRandom.current().nextBytes(content);
    Buffer buffer = allocator.wrap(content);
    HttpHeaders trailers = INSTANCE.newTrailers();
    trailers.add("TrailerStatus", "good");
    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(TRANSFER_ENCODING, CHUNKED);
    channel.writeOutbound(request);
    channel.writeOutbound(buffer.duplicate());
    channel.writeOutbound(trailers);
    verifyHttpRequest(channel, buffer, TransferEncoding.Chunked, true);
    assertFalse(channel.finishAndReleaseAll());
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpHeaders(io.servicetalk.http.api.HttpHeaders) EmptyHttpHeaders(io.servicetalk.http.api.EmptyHttpHeaders) HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with HttpRequestMetaData

use of io.servicetalk.http.api.HttpRequestMetaData in project servicetalk by apple.

the class HttpRequestEncoderTest method chunkedNoTrailers.

@Test
void chunkedNoTrailers() {
    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(TRANSFER_ENCODING, CHUNKED);
    channel.writeOutbound(request);
    channel.writeOutbound(buffer.duplicate());
    channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
    verifyHttpRequest(channel, buffer, TransferEncoding.Chunked, false);
    assertFalse(channel.finishAndReleaseAll());
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpRequestMetaData(io.servicetalk.http.api.HttpRequestMetaData) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HttpRequestMetaData (io.servicetalk.http.api.HttpRequestMetaData)16 Test (org.junit.jupiter.api.Test)12 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Buffer (io.servicetalk.buffer.api.Buffer)9 DefaultHttpHeadersFactory (io.servicetalk.http.api.DefaultHttpHeadersFactory)4 HttpHeaders (io.servicetalk.http.api.HttpHeaders)4 ClientGroup (io.servicetalk.client.api.ClientGroup)3 ServiceDiscoverer (io.servicetalk.client.api.ServiceDiscoverer)3 AVAILABLE (io.servicetalk.client.api.ServiceDiscovererEvent.Status.AVAILABLE)3 DefaultPartitionAttributesBuilder (io.servicetalk.client.api.internal.partition.DefaultPartitionAttributesBuilder)3 PartitionAttributes (io.servicetalk.client.api.partition.PartitionAttributes)3 PartitionAttributesBuilder (io.servicetalk.client.api.partition.PartitionAttributesBuilder)3 PartitionedServiceDiscovererEvent (io.servicetalk.client.api.partition.PartitionedServiceDiscovererEvent)3 AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)3 Publisher (io.servicetalk.concurrent.api.Publisher)3 Single (io.servicetalk.concurrent.api.Single)3 TestPublisher (io.servicetalk.concurrent.api.TestPublisher)3 TestSubscription (io.servicetalk.concurrent.api.TestSubscription)3 BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)3