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();
}
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());
}
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());
}
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());
}
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());
}
Aggregations