use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.
the class HttpResponseDecoderTest method variableWithContent.
@Test
void variableWithContent() {
int contentLength = 128;
writeMsg("HTTP/1.1 200 OK" + "\r\n" + "Host: servicetalk.io" + "\r\n" + "Connection: keep-alive" + "\r\n" + "\r\n");
writeContent(contentLength);
// For a response, the variable length content is considered "complete" when the channel is closed.
channel.close();
HttpMetaData metaData = assertStartLineForContent();
assertStandardHeaders(metaData.headers());
assertThat(metaData.headers().get(CONTENT_LENGTH), is(nullValue()));
Buffer chunk = channel().readInbound();
assertThat(chunk.readableBytes(), is(contentLength));
assertEmptyTrailers(channel());
assertFalse(channel.finishAndReleaseAll());
}
use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.
the class HttpResponseDecoderTest method variableWithChunkedContentAndTrailers.
@Test
void variableWithChunkedContentAndTrailers() {
int chunkSize = 128;
writeMsg("HTTP/1.1 200 OK" + "\r\n" + "Host: servicetalk.io" + "\r\n" + "Connection: keep-alive" + "\r\n" + "\r\n");
// Note that trailers are only allowed when chunked encoding is used. So the trailers in this case are
// considered part of the payload (even the \r\n), and the response is terminated when the channel is closed.
// https://tools.ietf.org/html/rfc7230.html#section-4.1
writeChunk(chunkSize);
writeChunk(0);
String trailersPart = "TrailerStatus: good" + "\r\n";
writeMsg(trailersPart);
writeMsg("\r\n");
// For a response, the variable length content is considered "complete" when the channel is closed.
channel.close();
// In this case, content is parsed without taking "chunked" encoding into account.
int expectedContentLength = 2 + /* chunk-size */
2 + /* CRLF */
chunkSize + 2 + /* CRLF */
3 + /* last-chunk */
trailersPart.length() + 2;
HttpMetaData metaData = assertStartLineForContent();
assertStandardHeaders(metaData.headers());
assertThat(isTransferEncodingChunked(metaData.headers()), is(false));
HttpHeaders trailers = assertPayloadSize(expectedContentLength);
assertThat("Trailers are not empty", trailers, nullValue());
assertFalse(channel.finishAndReleaseAll());
}
Aggregations