Search in sources :

Example 1 with HttpResponseMetaData

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

the class HttpResponseDecoderBenchmark method initialLine.

@Benchmark
public int initialLine() {
    channel.writeInbound(responseByteBuf.duplicate());
    final HttpResponseMetaData response = channel.readInbound();
    final HttpHeaders trailers = channel.readInbound();
    if (response.status().code() != statusCode) {
        throw new IllegalStateException("Unexpected statusCode: " + response.status().code());
    }
    return response.headers().size() + trailers.size();
}
Also used : HttpHeaders(io.servicetalk.http.api.HttpHeaders) HttpResponseMetaData(io.servicetalk.http.api.HttpResponseMetaData) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 2 with HttpResponseMetaData

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

the class HttpResponseEncoderTest method contentLengthWithTrailers.

@ParameterizedTest
@ValueSource(booleans = { true, false })
void contentLengthWithTrailers(boolean emptyTrailers) {
    EmbeddedChannel channel = newEmbeddedChannel();
    byte[] content = new byte[128];
    ThreadLocalRandom.current().nextBytes(content);
    Buffer buffer = DEFAULT_ALLOCATOR.wrap(content);
    HttpHeaders trailers = DefaultHttpHeadersFactory.INSTANCE.newTrailers();
    if (!emptyTrailers) {
        trailers.add("TrailerStatus", "good");
    }
    HttpResponseMetaData response = newResponseMetaData(HTTP_1_1, OK, INSTANCE.newHeaders());
    response.headers().add(CONNECTION, KEEP_ALIVE).add(SERVER, "unit-test").add(CONTENT_LENGTH, valueOf(content.length));
    channel.writeOutbound(response);
    channel.writeOutbound(buffer.duplicate());
    if (!emptyTrailers) {
        assertThrows(IOException.class, () -> channel.writeOutbound(trailers));
    } else {
        channel.writeOutbound(trailers);
        verifyHttpResponse(channel, buffer, TransferEncoding.ContentLength, false);
        consumeEmptyBufferFromTrailers(channel);
    }
    // The trailers will just not be encoded if the transfer encoding is not set correctly.
    assertNotEquals(emptyTrailers, channel.finishAndReleaseAll());
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpHeaders(io.servicetalk.http.api.HttpHeaders) EmptyHttpHeaders(io.servicetalk.http.api.EmptyHttpHeaders) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponseMetaData(io.servicetalk.http.api.HttpResponseMetaData) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with HttpResponseMetaData

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

the class HttpResponseEncoderTest method chunkedNoTrailersNoContent.

@Test
void chunkedNoTrailersNoContent() {
    EmbeddedChannel channel = newEmbeddedChannel();
    HttpResponseMetaData response = newResponseMetaData(HTTP_1_1, OK, INSTANCE.newHeaders());
    response.headers().add(CONNECTION, KEEP_ALIVE).add(SERVER, "unit-test").add(TRANSFER_ENCODING, CHUNKED);
    channel.writeOutbound(response);
    channel.writeOutbound(EMPTY_BUFFER.duplicate());
    channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
    verifyHttpResponse(channel, EMPTY_BUFFER, TransferEncoding.Chunked, false);
    assertFalse(channel.finishAndReleaseAll());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponseMetaData(io.servicetalk.http.api.HttpResponseMetaData) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with HttpResponseMetaData

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

the class HttpResponseEncoderTest method chunkedNoTrailers.

@Test
void chunkedNoTrailers() {
    EmbeddedChannel channel = newEmbeddedChannel();
    byte[] content = new byte[128];
    ThreadLocalRandom.current().nextBytes(content);
    Buffer buffer = DEFAULT_ALLOCATOR.wrap(content);
    HttpResponseMetaData response = newResponseMetaData(HTTP_1_1, OK, INSTANCE.newHeaders());
    response.headers().add(CONNECTION, KEEP_ALIVE).add(SERVER, "unit-test").add(TRANSFER_ENCODING, CHUNKED);
    channel.writeOutbound(response);
    channel.writeOutbound(buffer.duplicate());
    channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
    verifyHttpResponse(channel, buffer, TransferEncoding.Chunked, false);
    assertFalse(channel.finishAndReleaseAll());
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponseMetaData(io.servicetalk.http.api.HttpResponseMetaData) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with HttpResponseMetaData

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

the class HttpResponseEncoderTest method variableNoTrailersNoContent.

@Test
void variableNoTrailersNoContent() {
    EmbeddedChannel channel = newEmbeddedChannel();
    HttpResponseMetaData response = newResponseMetaData(HTTP_1_1, OK, INSTANCE.newHeaders());
    response.headers().add(CONNECTION, KEEP_ALIVE).add(SERVER, "unit-test");
    channel.writeOutbound(response);
    channel.writeOutbound(EMPTY_BUFFER.duplicate());
    channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
    verifyHttpResponse(channel, EMPTY_BUFFER, TransferEncoding.Variable, false);
    assertFalse(channel.finishAndReleaseAll());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponseMetaData(io.servicetalk.http.api.HttpResponseMetaData) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HttpResponseMetaData (io.servicetalk.http.api.HttpResponseMetaData)17 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)11 Buffer (io.servicetalk.buffer.api.Buffer)11 Test (org.junit.jupiter.api.Test)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 HttpHeaders (io.servicetalk.http.api.HttpHeaders)7 EmptyHttpHeaders (io.servicetalk.http.api.EmptyHttpHeaders)3 Publisher (io.servicetalk.concurrent.api.Publisher)2 StreamingHttpRequest (io.servicetalk.http.api.StreamingHttpRequest)2 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)2 Integer.toHexString (java.lang.Integer.toHexString)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 ByteBuf (io.netty.buffer.ByteBuf)1 HT (io.netty.handler.codec.http.HttpConstants.HT)1 Http2Headers (io.netty.handler.codec.http2.Http2Headers)1 DefaultHttpHeadersFactory (io.servicetalk.http.api.DefaultHttpHeadersFactory)1 GET (io.servicetalk.http.api.HttpRequestMethod.GET)1 Benchmark (org.openjdk.jmh.annotations.Benchmark)1