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);
}
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());
}
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);
}
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());
}
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;
}
Aggregations