use of io.netty.handler.codec.http.HttpRequest in project riposte by Nike-Inc.
the class VerifyDecoderFailedResultIsHandledTest method proxy_endpoints_should_handle_decode_exception.
@Test
public void proxy_endpoints_should_handle_decode_exception() throws Exception {
// given
int payloadSize = 10000;
ByteBuf payload = ComponentTestUtils.createByteBufPayload(payloadSize);
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, RouterEndpoint.MATCHING_PATH, payload);
//leave off content-length and transfer-encoding to trigger DecoderFailedResult
request.headers().set(HttpHeaders.Names.HOST, "localhost");
// when
Pair<Integer, String> serverResponse = executeRequest(request, proxyServerConfig.endpointsPort(), incompleteCallTimeoutMillis);
// then
assertErrorResponse(serverResponse);
}
use of io.netty.handler.codec.http.HttpRequest in project riposte by Nike-Inc.
the class HttpUtilsTest method extractCookies_works_if_cookies_defined_in_headers.
@Test
public void extractCookies_works_if_cookies_defined_in_headers() {
// given
Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));
HttpRequest nettyRequestMock = mock(HttpRequest.class);
doReturn(headers).when(nettyRequestMock).headers();
// when
Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);
// then
assertThat(extractedCookies.contains(cookie1), is(true));
assertThat(extractedCookies.contains(cookie2), is(true));
}
use of io.netty.handler.codec.http.HttpRequest in project riposte by Nike-Inc.
the class HttpUtilsTest method extractCookies_does_not_use_trailing_headers_if_trailing_headers_is_null.
@Test
public void extractCookies_does_not_use_trailing_headers_if_trailing_headers_is_null() {
// given
HttpRequest nettyRequestMock = mock(HttpRequest.class);
doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).headers();
// when
Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);
// then
assertThat(extractedCookies, notNullValue());
assertThat(extractedCookies.isEmpty(), is(true));
}
use of io.netty.handler.codec.http.HttpRequest in project riposte by Nike-Inc.
the class RequestInfoImpl method getMultipartParts.
/**
* {@inheritDoc}
*/
@Override
public synchronized List<InterfaceHttpData> getMultipartParts() {
if (!isMultipartRequest() || !isCompleteRequestWithAllChunks())
return null;
if (multipartData == null) {
byte[] contentBytes = getRawContentBytes();
HttpRequest fullHttpRequestForMultipartDecoder = (contentBytes == null) ? new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri()) : new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri(), Unpooled.wrappedBuffer(contentBytes));
fullHttpRequestForMultipartDecoder.headers().add(getHeaders());
multipartData = new HttpPostMultipartRequestDecoder(new DefaultHttpDataFactory(false), fullHttpRequestForMultipartDecoder, getContentCharset());
}
return multipartData.getBodyHttpDatas();
}
use of io.netty.handler.codec.http.HttpRequest in project riposte by Nike-Inc.
the class VerifyProxyRequestsDoNotAlterRequestToDownstreamServiceTest method proxy_endpoints_should_honor_chunked_transfer_encoding.
@Test
public void proxy_endpoints_should_honor_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.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
// 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 sent in chunks
//https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6.1
assertThat(downstreamBody).contains("\r\n");
assertThat(proxyBody).contains("\r\n");
//assert bodies are equal
String proxyBodyMinusChunkInfo = extractFullBodyFromChunks(proxyBody);
String downstreamBodyMinusChunkInfo = extractFullBodyFromChunks(downstreamBody);
//assert proxy and downstream have same bodies
assertThat(proxyBodyMinusChunkInfo).isEqualTo(downstreamBodyMinusChunkInfo);
//assert input payload matches proxy and downstream payloads
assertThat(proxyBodyMinusChunkInfo).isEqualTo(payloadString);
assertThat(downstreamBodyMinusChunkInfo).isEqualTo(payloadString);
}
Aggregations