Search in sources :

Example 86 with DefaultFullHttpRequest

use of io.netty.handler.codec.http.DefaultFullHttpRequest in project riposte by Nike-Inc.

the class VerifyRequestSizeValidationComponentTest method should_return_expected_response_when_chunked_request_not_exceeding_endpoint_overridden_request_size.

@Test
public void should_return_expected_response_when_chunked_request_not_exceeding_endpoint_overridden_request_size() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH, Unpooled.wrappedBuffer(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.MAX_REQUEST_SIZE).getBytes(UTF_8)));
    request.headers().set(HttpHeaders.Names.HOST, "127.0.0.1");
    request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    request.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, CHUNKED);
    // when
    Pair<Integer, String> serverResponse = executeRequest(request, serverConfig.endpointsPort(), incompleteCallTimeoutMillis);
    // then
    assertThat(serverResponse.getLeft()).isEqualTo(HttpResponseStatus.OK.code());
    assertThat(serverResponse.getRight()).isEqualTo(BasicEndpointWithRequestSizeValidationOverride.RESPONSE_PAYLOAD);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.Test)

Example 87 with DefaultFullHttpRequest

use of io.netty.handler.codec.http.DefaultFullHttpRequest in project riposte by Nike-Inc.

the class VerifyRequestSizeValidationComponentTest method should_return_bad_request_when_chunked_request_exceeds_global_configured_max_request_size.

@Test
public void should_return_bad_request_when_chunked_request_exceeds_global_configured_max_request_size() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, BasicEndpoint.MATCHING_PATH, Unpooled.wrappedBuffer(generatePayloadOfSizeInBytes(GLOBAL_MAX_REQUEST_SIZE + 1).getBytes(UTF_8)));
    request.headers().set(HttpHeaders.Names.HOST, "127.0.0.1");
    request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    request.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, CHUNKED);
    // when
    Pair<Integer, String> serverResponse = executeRequest(request, serverConfig.endpointsPort(), incompleteCallTimeoutMillis);
    // then
    assertThat(serverResponse.getLeft()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
    assertBadRequestErrorMessageAndMetadata(serverResponse.getRight());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.Test)

Example 88 with DefaultFullHttpRequest

use of io.netty.handler.codec.http.DefaultFullHttpRequest in project riposte by Nike-Inc.

the class VerifyProxyRequestsDoNotAlterRequestToDownstreamServiceTest method proxy_endpoints_should_honor_non_chunked_transfer_encoding.

@Test
public void proxy_endpoints_should_honor_non_chunked_transfer_encoding() throws Exception {
    // given
    int payloadSize = 10000;
    ByteBuf payload = createPayload(payloadSize);
    String payloadString = payload.toString(CharsetUtil.UTF_8);
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, RouterEndpoint.MATCHING_PATH, payload);
    request.headers().set(HttpHeaders.Names.HOST, "localhost");
    request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, payloadSize);
    // when
    Pair<Integer, String> serverResponse = executeRequest(request, proxyServerConfig.endpointsPort(), incompleteCallTimeoutMillis);
    // then
    assertThat(serverResponse.getRight()).isEqualTo(DownstreamEndpoint.RESPONSE_PAYLOAD);
    assertThat(serverResponse.getLeft()).isEqualTo(HttpResponseStatus.OK.code());
    assertProxyAndDownstreamServiceHeadersAndTracingHeadersAdded();
    String proxyBody = extractBodyFromRawRequest(proxyServerRequest.toString());
    String downstreamBody = extractBodyFromRawRequest(downstreamServerRequest.toString());
    //assert request was NOT sent in chunks
    //https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1
    assertThat(proxyBody).doesNotContain("\r\n");
    assertThat(downstreamBody).doesNotContain("\r\n");
    //assert bodies are equal
    assertThat(proxyBody).isEqualTo(downstreamBody);
    //assert input payload matches proxy and downstream payloads
    assertThat(proxyBody).isEqualTo(payloadString);
    assertThat(downstreamBody).isEqualTo(payloadString);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBuf(io.netty.buffer.ByteBuf) ProxyRouterEndpoint(com.nike.riposte.server.http.ProxyRouterEndpoint) Endpoint(com.nike.riposte.server.http.Endpoint) StandardEndpoint(com.nike.riposte.server.http.StandardEndpoint) Test(org.junit.Test)

Example 89 with DefaultFullHttpRequest

use of io.netty.handler.codec.http.DefaultFullHttpRequest in project riposte by Nike-Inc.

the class VerifyRequestSizeValidationComponentTest method should_return_bad_request_when_chunked_request_exceeds_endpoint_overridden_configured_max_request_size.

@Test
public void should_return_bad_request_when_chunked_request_exceeds_endpoint_overridden_configured_max_request_size() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, BasicEndpointWithRequestSizeValidationOverride.MATCHING_PATH, Unpooled.wrappedBuffer(generatePayloadOfSizeInBytes(BasicEndpointWithRequestSizeValidationOverride.MAX_REQUEST_SIZE + 1).getBytes(UTF_8)));
    request.headers().set(HttpHeaders.Names.HOST, "127.0.0.1");
    request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    request.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, CHUNKED);
    // when
    Pair<Integer, String> serverResponse = executeRequest(request, serverConfig.endpointsPort(), incompleteCallTimeoutMillis);
    // then
    assertThat(serverResponse.getLeft()).isEqualTo(HttpResponseStatus.BAD_REQUEST.code());
    assertBadRequestErrorMessageAndMetadata(serverResponse.getRight());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.Test)

Example 90 with DefaultFullHttpRequest

use of io.netty.handler.codec.http.DefaultFullHttpRequest in project motan by weibocom.

the class NettyHttpRequestHandlerTest method buildHttpRequest.

private FullHttpRequest buildHttpRequest(String requestPath) throws Exception {
    PooledByteBufAllocator allocator = new PooledByteBufAllocator();
    ByteBuf buf = allocator.buffer(0);
    FullHttpRequest httpReqeust = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, requestPath, buf);
    return httpReqeust;
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBuf(io.netty.buffer.ByteBuf) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator)

Aggregations

DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)92 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)53 Test (org.junit.Test)53 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)31 AsciiString (io.netty.util.AsciiString)28 ByteBuf (io.netty.buffer.ByteBuf)27 HttpRequest (io.netty.handler.codec.http.HttpRequest)22 ChannelPromise (io.netty.channel.ChannelPromise)15 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)11 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)11 URI (java.net.URI)9 Channel (io.netty.channel.Channel)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)8 Bootstrap (io.netty.bootstrap.Bootstrap)7 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)7 File (java.io.File)7 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)6 Map (java.util.Map)6 NullDispatcher (org.elasticsearch.http.NullDispatcher)6