use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.
the class HttpObjectDecoderTest method chunkedNoContentNoTrailers.
private void chunkedNoContentNoTrailers(boolean crlf) {
EmbeddedChannel channel = channel(crlf);
String br = br(crlf);
writeMsg(startLineForContent() + br + "Host: servicetalk.io" + br + "Connection: keep-alive" + br + "Transfer-Encoding: chunked" + br + br, channel);
writeLastChunk(channel);
HttpMetaData metaData = assertStartLineForContent(channel);
assertStandardHeaders(metaData.headers());
assertEmptyTrailers(channel);
assertFalse(channel.finishAndReleaseAll());
}
use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.
the class AbstractH2DuplexHandlerTest method noDataFramesForEmptyBuffers.
@ParameterizedTest
@EnumSource(Variant.class)
void noDataFramesForEmptyBuffers(Variant variant) {
setUp(variant);
Buffer[] payload = { EMPTY_BUFFER, DEFAULT_ALLOCATOR.fromAscii("data"), EMPTY_BUFFER };
HttpMetaData msg;
switch(variant) {
case CLIENT_HANDLER:
StreamingHttpRequest request = newRequest(GET, "/", HTTP_2_0, HEADERS_FACTORY.newHeaders(), DEFAULT_ALLOCATOR, HEADERS_FACTORY);
request.payloadBody(from(payload));
msg = request;
break;
case SERVER_HANDLER:
StreamingHttpResponse response = newResponse(HttpResponseStatus.OK, HTTP_2_0, HEADERS_FACTORY.newHeaders(), DEFAULT_ALLOCATOR, HEADERS_FACTORY);
response.payloadBody(from(payload));
msg = response;
break;
default:
throw new IllegalStateException("Unexpected variant: " + variant);
}
channel.writeOutbound(msg);
verify(closeHandler).protocolPayloadBeginOutbound(any());
verify(closeHandler, never()).protocolPayloadEndOutbound(any(), any());
for (Buffer buffer : payload) {
channel.writeOutbound(buffer);
}
verify(closeHandler, never()).protocolPayloadEndOutbound(any(), any());
channel.writeOutbound(EmptyHttpHeaders.INSTANCE);
verify(closeHandler).protocolPayloadEndOutbound(any(), any());
Http2HeadersFrame headersFrame = channel.readOutbound();
assertThat("Unexpected endStream flag value at headers frame", headersFrame.isEndStream(), is(false));
assertEmptyDataFrame();
Http2DataFrame dataFrame = channel.readOutbound();
assertThat("Unexpected data", dataFrame.content().toString(US_ASCII), is("data"));
assertThat("Unexpected endStream flag value at data frame", dataFrame.isEndStream(), is(false));
assertEmptyDataFrame();
dataFrame = channel.readOutbound();
assertThat("Unexpected endStream flag value at last frame", dataFrame.isEndStream(), is(true));
assertThat("Unexpected outbound messages", channel.outboundMessages(), empty());
}
use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.
the class AbstractH2DuplexHandlerTest method emptyMessageWrittenAsSingleFrame.
@ParameterizedTest
@EnumSource(Variant.class)
void emptyMessageWrittenAsSingleFrame(Variant variant) {
setUp(variant);
HttpMetaData msg;
switch(variant) {
case CLIENT_HANDLER:
msg = newRequest(GET, "/", HTTP_2_0, HEADERS_FACTORY.newHeaders(), DEFAULT_ALLOCATOR, HEADERS_FACTORY);
break;
case SERVER_HANDLER:
msg = newResponse(HttpResponseStatus.OK, HTTP_2_0, HEADERS_FACTORY.newHeaders(), DEFAULT_ALLOCATOR, HEADERS_FACTORY);
break;
default:
throw new IllegalStateException("Unexpected variant: " + variant);
}
channel.writeOutbound(msg);
verify(closeHandler).protocolPayloadBeginOutbound(any());
verify(closeHandler).protocolPayloadEndOutbound(any(), any());
Http2HeadersFrame frame = channel.readOutbound();
assertThat("Unexpected endStream flag value", frame.isEndStream(), is(true));
assertThat("Unexpected outbound messages", channel.outboundMessages(), empty());
}
use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.
the class AbstractH2DuplexHandlerTest method responseWithContentLengthToHeadRequest.
private void responseWithContentLengthToHeadRequest(Variant variant, boolean endStream) {
Assumptions.assumeTrue(variant == Variant.CLIENT_HANDLER, "Only relevant for the client-side");
int contentLength = 1;
// Send HEAD request
channel.writeOutbound(newRequest(HEAD, "/", HTTP_2_0, HEADERS_FACTORY.newHeaders(), DEFAULT_ALLOCATOR, HEADERS_FACTORY), true);
// Prepare server response with content-length header:
Http2Headers headers = new DefaultHttp2Headers();
headers.status(OK.codeAsText());
headers.setInt(CONTENT_LENGTH, contentLength);
channel.writeInbound(headersFrame(headers, endStream));
HttpMetaData metaData = channel.readInbound();
assertThat(metaData.headers().get(CONTENT_LENGTH), contentEqualTo(valueOf(contentLength)));
if (endStream) {
HttpHeaders trailers = channel.readInbound();
if (trailers != null) {
assertThat(trailers.isEmpty(), is(true));
}
} else {
// No more items at this moment:
assertThat(channel.inboundMessages(), is(empty()));
channel.writeInbound(headersFrame(new DefaultHttp2Headers(), true));
HttpHeaders trailers = channel.readInbound();
assertThat(trailers.isEmpty(), is(true));
}
assertThat(channel.inboundMessages(), is(empty()));
}
use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.
the class AbstractH2DuplexHandlerTest method withContentLength.
private void withContentLength(Variant variant, boolean addTrailers) {
variant.writeOutbound(channel);
String content = "hello";
Http2Headers headers = variant.setHeaders(new DefaultHttp2Headers());
headers.setInt(CONTENT_LENGTH, content.length());
channel.writeInbound(headersFrame(headers, false));
HttpMetaData metaData = channel.readInbound();
assertThat(metaData.headers().get(CONTENT_LENGTH), contentEqualTo(valueOf(content.length())));
channel.writeInbound(new DefaultHttp2DataFrame(writeAscii(UnpooledByteBufAllocator.DEFAULT, content), !addTrailers));
Buffer buffer = channel.readInbound();
assertThat(buffer, is(equalTo(DEFAULT_ALLOCATOR.fromAscii(content))));
if (addTrailers) {
channel.writeInbound(headersFrame(new DefaultHttp2Headers().set("trailer", "value"), true));
}
HttpHeaders trailers = channel.readInbound();
if (trailers != null) {
assertThat(trailers.isEmpty(), is(!addTrailers));
}
assertThat(channel.inboundMessages(), is(empty()));
}
Aggregations