use of io.servicetalk.http.api.HttpResponseMetaData in project servicetalk by apple.
the class HttpResponseEncoderTest method contentLengthNoTrailersHeaderWhiteSpaceEncodedWithValidationOff.
@Test
void contentLengthNoTrailersHeaderWhiteSpaceEncodedWithValidationOff() {
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, new DefaultHttpHeadersFactory(false, false, false).newHeaders());
response.headers().add(" " + CONNECTION + " ", " " + KEEP_ALIVE).add(" " + SERVER + " ", " unit-test ").add(CONTENT_LENGTH, valueOf(content.length));
channel.writeOutbound(response);
channel.writeOutbound(buffer.duplicate());
ByteBuf byteBuf = channel.readOutbound();
String actualMetaData = byteBuf.toString(US_ASCII);
byteBuf.release();
assertTrue(actualMetaData.contains("HTTP/1.1 200 OK" + "\r\n"), () -> "unexpected metadata: " + actualMetaData);
assertTrue(actualMetaData.contains(" " + CONNECTION + " : " + KEEP_ALIVE + "\r\n"), () -> "unexpected metadata: " + actualMetaData);
assertTrue(actualMetaData.contains(" " + SERVER + " : unit-test " + "\r\n"), () -> "unexpected metadata: " + actualMetaData);
assertTrue(actualMetaData.contains(CONTENT_LENGTH + ": " + buffer.readableBytes() + "\r\n"), () -> "unexpected metadata: " + actualMetaData);
assertTrue(actualMetaData.endsWith("\r\n" + "\r\n"), () -> "unexpected metadata: " + actualMetaData);
byteBuf = channel.readOutbound();
assertEquals(buffer.toNioBuffer(), byteBuf.nioBuffer());
byteBuf.release();
assertFalse(channel.finishAndReleaseAll());
}
use of io.servicetalk.http.api.HttpResponseMetaData in project servicetalk by apple.
the class HttpResponseEncoderTest method chunkedWithTrailers.
@Test
void chunkedWithTrailers() {
EmbeddedChannel channel = newEmbeddedChannel();
byte[] content = new byte[128];
ThreadLocalRandom.current().nextBytes(content);
Buffer buffer = DEFAULT_ALLOCATOR.wrap(content);
HttpHeaders trailers = DefaultHttpHeadersFactory.INSTANCE.newTrailers();
trailers.add("TrailerStatus", "good");
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(trailers);
verifyHttpResponse(channel, buffer, TransferEncoding.Chunked, true);
assertFalse(channel.finishAndReleaseAll());
}
Aggregations