use of io.servicetalk.http.api.DefaultHttpHeadersFactory in project servicetalk by apple.
the class HttpRequestEncoderTest method contentLengthNoTrailersHeaderWhiteSpaceEncodedWithValidationOff.
@Test
void contentLengthNoTrailersHeaderWhiteSpaceEncodedWithValidationOff() {
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", new DefaultHttpHeadersFactory(false, false, false).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());
ByteBuf byteBuf = channel.readOutbound();
String actualMetaData = byteBuf.toString(US_ASCII);
byteBuf.release();
assertTrue(actualMetaData.contains("GET /some/path?foo=bar&baz=yyy HTTP/1.1" + "\r\n"), () -> "unexpected metadata: " + actualMetaData);
assertTrue(actualMetaData.contains(" " + CONNECTION + " : " + KEEP_ALIVE + "\r\n"), () -> "unexpected metadata: " + actualMetaData);
assertTrue(actualMetaData.contains(" " + USER_AGENT + " : 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.DefaultHttpHeadersFactory 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());
}
Aggregations