use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class HttpServletRequestWrapperForRequestInfoTest method beforeMethod.
@Before
public void beforeMethod() {
headers = new DefaultHttpHeaders();
attributes = new HashMap<>();
requestInfoMock = mock(RequestInfo.class);
doReturn(headers).when(requestInfoMock).getHeaders();
doReturn(attributes).when(requestInfoMock).getRequestAttributes();
isSsl = false;
wrapper = new HttpServletRequestWrapperForRequestInfo<>(requestInfoMock, isSsl);
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class HttpUtilsTest method extractCookies_returns_empty_set_if_no_cookies_defined.
@Test
public void extractCookies_returns_empty_set_if_no_cookies_defined() {
// given
FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).headers();
doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).trailingHeaders();
// when
Set<Cookie> extractedCookies = HttpUtils.extractCookies(nettyRequestMock);
// then
assertThat(extractedCookies, notNullValue());
assertThat(extractedCookies.isEmpty(), is(true));
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class RequestInfoImplTest method uber_constructor_works_for_valid_values.
@Test
public void uber_constructor_works_for_valid_values() {
// given
String uri = "/some/uri/path/%24foobar%26?notused=blah";
HttpMethod method = HttpMethod.PATCH;
Charset contentCharset = CharsetUtil.US_ASCII;
HttpHeaders headers = new DefaultHttpHeaders().add("header1", "val1").add(HttpHeaders.Names.CONTENT_TYPE, "text/text charset=" + contentCharset.displayName());
QueryStringDecoder queryParams = new QueryStringDecoder(uri + "?foo=bar&secondparam=secondvalue");
Set<Cookie> cookies = new HashSet<>(Arrays.asList(new DefaultCookie("cookie1", "val1"), new DefaultCookie("cookie2", "val2")));
Map<String, String> pathParams = Arrays.stream(new String[][] { { "pathParam1", "val1" }, { "pathParam2", "val2" } }).collect(Collectors.toMap(pair -> pair[0], pair -> pair[1]));
String content = UUID.randomUUID().toString();
byte[] contentBytes = content.getBytes();
LastHttpContent chunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(contentBytes));
chunk.trailingHeaders().add("trailingHeader1", "trailingVal1");
List<HttpContent> contentChunks = Collections.singletonList(chunk);
HttpVersion protocolVersion = HttpVersion.HTTP_1_1;
boolean keepAlive = true;
boolean fullRequest = true;
boolean isMultipart = false;
// when
RequestInfoImpl<?> requestInfo = new RequestInfoImpl<>(uri, method, headers, chunk.trailingHeaders(), queryParams, cookies, pathParams, contentChunks, protocolVersion, keepAlive, fullRequest, isMultipart);
// then
assertThat("getUri should return passed in value", requestInfo.getUri(), is(uri));
assertThat("getPath did not decode as expected", requestInfo.getPath(), is("/some/uri/path/$foobar&"));
assertThat(requestInfo.getMethod(), is(method));
assertThat(requestInfo.getHeaders(), is(headers));
assertThat(requestInfo.getTrailingHeaders(), is(chunk.trailingHeaders()));
assertThat(requestInfo.getQueryParams(), is(queryParams));
assertThat(requestInfo.getCookies(), is(cookies));
assertThat(requestInfo.pathTemplate, nullValue());
assertThat(requestInfo.pathParams, is(pathParams));
assertThat(requestInfo.getRawContentBytes(), is(contentBytes));
assertThat(requestInfo.getRawContent(), is(content));
assertThat(requestInfo.content, nullValue());
assertThat(requestInfo.getContentCharset(), is(contentCharset));
assertThat(requestInfo.getProtocolVersion(), is(protocolVersion));
assertThat(requestInfo.isKeepAliveRequested(), is(keepAlive));
assertThat(requestInfo.isCompleteRequestWithAllChunks, is(fullRequest));
assertThat(requestInfo.isMultipart, is(isMultipart));
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class BaseResponseInfoBuilderTest method builder_stores_values_as_expected.
@Test
public void builder_stores_values_as_expected() {
// given
String content = UUID.randomUUID().toString();
int httpStatusCode = 200;
HttpHeaders headers = new DefaultHttpHeaders();
String mimeType = "text/text";
Charset contentCharset = CharsetUtil.ISO_8859_1;
Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
boolean preventCompressedOutput = true;
// when
BaseResponseInfoBuilder<String> responseInfoBuilder = new BaseResponseInfoBuilder<String>() {
}.withHttpStatusCode(httpStatusCode).withHeaders(headers).withDesiredContentWriterMimeType(mimeType).withDesiredContentWriterEncoding(contentCharset).withCookies(cookies).withPreventCompressedOutput(preventCompressedOutput);
// then
assertThat(responseInfoBuilder.getHttpStatusCode(), is(httpStatusCode));
assertThat(responseInfoBuilder.getHeaders(), is(headers));
assertThat(responseInfoBuilder.getDesiredContentWriterMimeType(), is(mimeType));
assertThat(responseInfoBuilder.getDesiredContentWriterEncoding(), is(contentCharset));
assertThat(responseInfoBuilder.getCookies(), is(cookies));
assertThat(responseInfoBuilder.isPreventCompressedOutput(), is(preventCompressedOutput));
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class BaseResponseInfoTest method uber_constructor_for_full_response_sets_fields_as_expected.
@Test
public void uber_constructor_for_full_response_sets_fields_as_expected() {
// given
int httpStatusCode = 200;
HttpHeaders headers = new DefaultHttpHeaders();
String mimeType = "text/text";
Charset contentCharset = CharsetUtil.UTF_8;
Set<Cookie> cookies = Sets.newHashSet(new DefaultCookie("key1", "val1"), new DefaultCookie("key2", "val2"));
boolean preventCompressedResponse = true;
// when
BaseResponseInfo<?> responseInfo = createNewBaseResponseInfoForTesting(httpStatusCode, headers, mimeType, contentCharset, cookies, preventCompressedResponse);
// then
assertThat(responseInfo.getHttpStatusCode(), is(httpStatusCode));
assertThat(responseInfo.getHeaders(), is(headers));
assertThat(responseInfo.getDesiredContentWriterMimeType(), is(mimeType));
assertThat(responseInfo.getDesiredContentWriterEncoding(), is(contentCharset));
assertThat(responseInfo.getCookies(), is(cookies));
assertThat(responseInfo.getUncompressedRawContentLength(), nullValue());
assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedResponse));
assertThat(responseInfo.isResponseSendingStarted(), is(false));
assertThat(responseInfo.isResponseSendingLastChunkSent(), is(false));
}
Aggregations