use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.
the class RequestInfoForLoggingRiposteAdapterTest method getHeaderMapReturnsEmptyMapIfNettyHeaderNamesReturnsNull.
@Test
public void getHeaderMapReturnsEmptyMapIfNettyHeaderNamesReturnsNull() {
HttpHeaders headersMock = mock(HttpHeaders.class);
doReturn(null).when(headersMock).names();
setFieldOnRequestInfo("headers", headersMock);
Map<String, List<String>> actualHeaderMap = adapter.getHeadersMap();
assertThat(actualHeaderMap, notNullValue());
assertThat(actualHeaderMap.isEmpty(), is(true));
}
use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.
the class RequestInfoForLoggingRiposteAdapterTest method getHeadersDelegatesToRequestInfo.
@Test
public void getHeadersDelegatesToRequestInfo() {
Pair<String, List<String>> header1 = Pair.of("header1", Arrays.asList("h1val1"));
Pair<String, List<String>> header2 = Pair.of("header2", Arrays.asList("h2val1", "h2val2"));
Map<String, List<String>> expectedHeaderMap = new TreeMap<>(MapBuilder.<String, List<String>>builder().put(header1.getKey(), header1.getValue()).put(header2.getKey(), header2.getValue()).build());
HttpHeaders headersMock = mock(HttpHeaders.class);
doReturn(expectedHeaderMap.keySet()).when(headersMock).names();
for (Map.Entry<String, List<String>> entry : expectedHeaderMap.entrySet()) {
doReturn(entry.getValue()).when(headersMock).getAll(entry.getKey());
}
setFieldOnRequestInfo("headers", headersMock);
assertThat(adapter.getHeaders(header1.getKey()), is(header1.getValue()));
assertThat(adapter.getHeaders(header2.getKey()), is(header2.getValue()));
}
use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.
the class RequestInfoForLoggingRiposteAdapterTest method getHeaderMapDelegatesToRequestInfoAndCachesResult.
@Test
public void getHeaderMapDelegatesToRequestInfoAndCachesResult() {
Map<String, List<String>> expectedHeaderMap = new TreeMap<>(MapBuilder.<String, List<String>>builder().put("header1", Arrays.asList("h1val1")).put("header2", Arrays.asList("h2val1", "h2val2")).build());
HttpHeaders nettyHeaders = new DefaultHttpHeaders();
for (Map.Entry<String, List<String>> headerEntry : expectedHeaderMap.entrySet()) {
nettyHeaders.add(headerEntry.getKey(), headerEntry.getValue());
}
setFieldOnRequestInfo("headers", nettyHeaders);
Map<String, List<String>> actualHeaderMap = adapter.getHeadersMap();
assertThat(actualHeaderMap, is(expectedHeaderMap));
assertThat(adapter.getHeadersMap(), sameInstance(actualHeaderMap));
}
use of io.netty.handler.codec.http.HttpHeaders in project dubbo by alibaba.
the class HttpProcessHandler method http_200.
private static final FullHttpResponse http_200(String result) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(result.getBytes()));
HttpHeaders httpHeaders = response.headers();
httpHeaders.set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
httpHeaders.set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());
return response;
}
use of io.netty.handler.codec.http.HttpHeaders in project dubbo by alibaba.
the class HttpProcessHandler method http_500.
private static final FullHttpResponse http_500(String errorMessage) {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(errorMessage.getBytes()));
HttpHeaders httpHeaders = response.headers();
httpHeaders.set(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
httpHeaders.set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes());
return response;
}
Aggregations