Search in sources :

Example 1 with HttpMetaData

use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.

the class HttpResponseDecoderTest method smuggleBeforeNonZeroContentLengthHeader.

@Test
void smuggleBeforeNonZeroContentLengthHeader() {
    int contentLength = 128;
    writeMsg(startLineForContent() + "\r\n" + "Host: servicetalk.io" + "\r\n" + // [1] https://tools.ietf.org/html/rfc7230#section-3.3.3
    "Smuggled: " + startLine() + "\r\n\r\n" + "Content-Length: " + contentLength + "\r\n" + "Connection: keep-alive" + "\r\n\r\n");
    HttpMetaData metaData = assertStartLineForContent();
    assertSingleHeaderValue(metaData.headers(), HOST, "servicetalk.io");
    assertSingleHeaderValue(metaData.headers(), "Smuggled", startLine());
    Buffer buffer = channel().readInbound();
    assertThat(buffer.toString(US_ASCII), is("Content-Length: " + contentLength + "\r\nConnection: keep-alive\r\n\r\n"));
    channel().close();
    assertEmptyTrailers(channel());
    assertFalse(channel().finishAndReleaseAll());
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpMetaData(io.servicetalk.http.api.HttpMetaData) Test(org.junit.jupiter.api.Test)

Example 2 with HttpMetaData

use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.

the class HttpResponseDecoderTest method smuggleBeforeTransferEncodingHeader.

@Test
void smuggleBeforeTransferEncodingHeader() {
    writeMsg(startLineForContent() + "\r\n" + "Host: servicetalk.io" + "\r\n" + // [1] https://tools.ietf.org/html/rfc7230#section-3.3.3
    "Smuggled: " + startLine() + "\r\n\r\n" + TRANSFER_ENCODING + ": " + CHUNKED + "\r\n" + "Connection: keep-alive" + "\r\n\r\n");
    HttpMetaData metaData = assertStartLineForContent();
    assertSingleHeaderValue(metaData.headers(), HOST, "servicetalk.io");
    assertSingleHeaderValue(metaData.headers(), "Smuggled", startLine());
    Buffer buffer = channel().readInbound();
    assertThat(buffer.toString(US_ASCII), is(TRANSFER_ENCODING + ": " + CHUNKED + "\r\nConnection: keep-alive\r\n\r\n"));
    channel().close();
    assertEmptyTrailers(channel());
    assertFalse(channel().finishAndReleaseAll());
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpMetaData(io.servicetalk.http.api.HttpMetaData) Test(org.junit.jupiter.api.Test)

Example 3 with HttpMetaData

use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.

the class HttpObjectDecoderTest method chunkedWithContentLength.

private void chunkedWithContentLength(boolean crlf) {
    EmbeddedChannel channel = channel(crlf);
    String br = br(crlf);
    int chunkSize = 128;
    int chunkedContentLength = 2 + 2 + chunkSize + 2 + 5;
    writeMsg(startLineForContent() + br + "Host: servicetalk.io" + br + "Connection: keep-alive" + br + "Content-Length: " + chunkedContentLength + br + "Transfer-Encoding: chunked" + br + br, channel);
    writeChunk(chunkSize, channel);
    writeLastChunk(channel);
    HttpMetaData metaData = validateWithContent(-chunkSize, false, channel);
    assertThat("Unexpected content-length header(s)", metaData.headers().valuesIterator(CONTENT_LENGTH).hasNext(), is(false));
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Integer.toHexString(java.lang.Integer.toHexString) HttpMetaData(io.servicetalk.http.api.HttpMetaData)

Example 4 with HttpMetaData

use of io.servicetalk.http.api.HttpMetaData in project servicetalk by apple.

the class HttpObjectDecoderTest method testHeaderFiledValue.

private void testHeaderFiledValue(String fieldValue, String expectedFieldValue, boolean crlf) {
    EmbeddedChannel channel = channel(crlf);
    String br = br(crlf);
    writeMsg(startLine() + br + "Host:" + fieldValue + br + br, channel);
    HttpMetaData metaData = assertStartLine(channel);
    assertSingleHeaderValue(metaData.headers(), HOST, expectedFieldValue);
    assertEmptyTrailers(channel);
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Integer.toHexString(java.lang.Integer.toHexString) HttpMetaData(io.servicetalk.http.api.HttpMetaData)

Example 5 with HttpMetaData

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());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Integer.toHexString(java.lang.Integer.toHexString) HttpMetaData(io.servicetalk.http.api.HttpMetaData)

Aggregations

HttpMetaData (io.servicetalk.http.api.HttpMetaData)22 Test (org.junit.jupiter.api.Test)8 Integer.toHexString (java.lang.Integer.toHexString)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)6 DefaultHttp2HeadersFrame (io.netty.handler.codec.http2.DefaultHttp2HeadersFrame)6 Buffer (io.servicetalk.buffer.api.Buffer)6 HttpHeaders (io.servicetalk.http.api.HttpHeaders)6 Matchers.emptyString (org.hamcrest.Matchers.emptyString)6 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)4 Http2Headers (io.netty.handler.codec.http2.Http2Headers)4 EmptyHttpHeaders (io.servicetalk.http.api.EmptyHttpHeaders)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 DefaultHttp2DataFrame (io.netty.handler.codec.http2.DefaultHttp2DataFrame)2 Http2HeadersFrame (io.netty.handler.codec.http2.Http2HeadersFrame)2 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled.directBuffer (io.netty.buffer.Unpooled.directBuffer)1 Unpooled.unreleasableBuffer (io.netty.buffer.Unpooled.unreleasableBuffer)1 Unpooled.wrappedBuffer (io.netty.buffer.Unpooled.wrappedBuffer)1 DecoderException (io.netty.handler.codec.DecoderException)1