use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class HttpUtilsTest method determineCharsetFromContentType_works.
@Test
@DataProvider(value = { "text/text charset=US-ASCII | UTF-8 | US-ASCII", "text/text charset=us-ascii | UTF-8 | US-ASCII", "text/text | UTF-8 | UTF-8", " | UTF-8 | UTF-8", "null | UTF-8 | UTF-8" }, splitBy = "\\|")
public void determineCharsetFromContentType_works(String contentTypeHeader, String defaultCharsetString, String expectedCharsetString) {
// given
Charset defaultCharset = Charset.forName(defaultCharsetString);
Charset expectedCharset = Charset.forName(expectedCharsetString);
HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.CONTENT_TYPE, String.valueOf(contentTypeHeader));
// when
Charset actualCharset = HttpUtils.determineCharsetFromContentType(headers, defaultCharset);
// then
assertThat(actualCharset, is(expectedCharset));
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class HttpUtilsTest method extractCookies_works_if_cookies_defined_in_trailing_headers.
@Test
public void extractCookies_works_if_cookies_defined_in_trailing_headers() {
// given
Cookie cookie1 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
Cookie cookie2 = new DefaultCookie(UUID.randomUUID().toString(), UUID.randomUUID().toString());
HttpHeaders trailingHeaders = new DefaultHttpHeaders().add(HttpHeaders.Names.COOKIE, ClientCookieEncoder.LAX.encode(cookie1, cookie2));
FullHttpRequest nettyRequestMock = mock(FullHttpRequest.class);
doReturn(new DefaultHttpHeaders()).when(nettyRequestMock).headers();
doReturn(trailingHeaders).when(nettyRequestMock).trailingHeaders();
// 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.DefaultHttpHeaders 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.DefaultHttpHeaders 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.DefaultHttpHeaders in project riposte by Nike-Inc.
the class ChunkedResponseInfoTest method uber_constructor_for_chunked_response_sets_fields_as_expected.
@Test
public void uber_constructor_for_chunked_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
ChunkedResponseInfo responseInfo = new ChunkedResponseInfo(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.getFinalContentLength(), nullValue());
assertThat(responseInfo.isPreventCompressedOutput(), is(preventCompressedResponse));
assertThat(responseInfo.isChunkedResponse(), is(true));
assertThat(responseInfo.isResponseSendingStarted(), is(false));
assertThat(responseInfo.isResponseSendingLastChunkSent(), is(false));
}
Aggregations