use of io.servicetalk.http.api.HttpResponseMetaData in project servicetalk by apple.
the class HttpResponseEncoderTest method withContentLengthAndChunked.
@Test
void withContentLengthAndChunked() {
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(CONTENT_LENGTH, valueOf(content.length)).add(TRANSFER_ENCODING, CHUNKED);
channel.writeOutbound(response);
channel.writeOutbound(buffer.duplicate());
channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
String metaData = verifyHttpResponse(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());
}
use of io.servicetalk.http.api.HttpResponseMetaData in project servicetalk by apple.
the class HttpResponseEncoderTest method variableNoTrailers.
@Test
void variableNoTrailers() {
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");
channel.writeOutbound(response);
channel.writeOutbound(buffer.duplicate());
channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
verifyHttpResponse(channel, buffer, TransferEncoding.Variable, false);
assertFalse(channel.finishAndReleaseAll());
}
use of io.servicetalk.http.api.HttpResponseMetaData in project servicetalk by apple.
the class HttpResponseEncoderTest method contentLengthNoTrailersHeaderWhiteSpaceThrowByDefault.
@Test
void contentLengthNoTrailersHeaderWhiteSpaceThrowByDefault() {
EmbeddedChannel channel = newEmbeddedChannel();
HttpResponseMetaData response = newResponseMetaData(HTTP_1_1, OK, INSTANCE.newHeaders());
assertThrows(IllegalArgumentException.class, () -> response.addHeader(" " + CONNECTION, KEEP_ALIVE));
assertFalse(channel.finishAndReleaseAll());
}
use of io.servicetalk.http.api.HttpResponseMetaData in project servicetalk by apple.
the class HttpResponseEncoderTest method contentLengthNoTrailers.
@Test
void contentLengthNoTrailers() {
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(CONTENT_LENGTH, valueOf(content.length));
channel.writeOutbound(response);
channel.writeOutbound(buffer.duplicate());
channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
verifyHttpResponse(channel, buffer, TransferEncoding.ContentLength, false);
consumeEmptyBufferFromTrailers(channel);
assertFalse(channel.finishAndReleaseAll());
}
use of io.servicetalk.http.api.HttpResponseMetaData in project servicetalk by apple.
the class HttpResponseEncoderTest method variableWithTrailers.
@ParameterizedTest
@ValueSource(booleans = { true, false })
void variableWithTrailers(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");
channel.writeOutbound(response);
channel.writeOutbound(buffer.duplicate());
if (!emptyTrailers) {
assertThrows(IOException.class, () -> channel.writeOutbound(trailers));
} else {
channel.writeOutbound(trailers);
verifyHttpResponse(channel, buffer, TransferEncoding.Variable, false);
}
// The trailers will just not be encoded if the transfer encoding is not set correctly.
assertNotEquals(emptyTrailers, channel.finishAndReleaseAll());
}
Aggregations