use of io.netty.handler.codec.http.DefaultHttpHeaders in project motan by weibocom.
the class NettyHttpRequestHandlerTest method testChannelRead0.
@Test
public void testChannelRead0() throws Exception {
final MessageHandler messageHandler = mockery.mock(MessageHandler.class);
final ChannelHandlerContext ctx = mockery.mock(ChannelHandlerContext.class);
final FullHttpResponse response = mockery.mock(FullHttpResponse.class);
mockery.checking(new Expectations() {
{
allowing(ctx).write(with(any(FullHttpResponse.class)));
will(new CustomAction("verify") {
@Override
public Object invoke(Invocation invocation) throws Throwable {
FullHttpResponse actualResponse = (FullHttpResponse) invocation.getParameter(0);
assertNotNull(actualResponse);
assertEquals(response, actualResponse);
return null;
}
});
allowing(ctx).flush();
will(returnValue(null));
allowing(ctx).close();
will(returnValue(null));
atLeast(1).of(messageHandler).handle(with(any(Channel.class)), with(anything()));
will(returnValue(response));
allowing(response).headers();
will(returnValue(new DefaultHttpHeaders()));
}
});
FullHttpRequest httpRequest = buildHttpRequest("anyPath");
NettyHttpRequestHandler handler = new NettyHttpRequestHandler(null, messageHandler);
handler.channelRead0(ctx, httpRequest);
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project undertow by undertow-io.
the class WebSocketTestClient method connect.
/**
* Connect the WebSocket client
*
* @throws Exception
*/
public WebSocketTestClient connect() throws Exception {
String protocol = uri.getScheme();
if (!"ws".equals(protocol)) {
throw new IllegalArgumentException("Unsupported protocol: " + protocol);
}
final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, version, null, false, new DefaultHttpHeaders());
EventLoopGroup group = new NioEventLoopGroup();
final CountDownLatch handshakeLatch = new CountDownLatch(1);
bootstrap.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer() {
@Override
protected void initChannel(Channel channel) throws Exception {
ChannelPipeline p = channel.pipeline();
p.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), new WSClientHandler(handshaker, handshakeLatch));
}
});
// Connect
ChannelFuture future = bootstrap.connect(new InetSocketAddress(uri.getHost(), uri.getPort()));
future.syncUninterruptibly();
ch = future.channel();
handshaker.handshake(ch).syncUninterruptibly();
handshakeLatch.await();
return this;
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project tesla by linking12.
the class HttpFiltersRunner method createResponse.
private HttpResponse createResponse(HttpResponseStatus httpResponseStatus, HttpRequest originalRequest) {
HttpHeaders httpHeaders = new DefaultHttpHeaders();
httpHeaders.add("Transfer-Encoding", "chunked");
HttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, httpResponseStatus);
httpResponse.headers().add(httpHeaders);
return httpResponse;
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class HttpServletResponseWrapperForResponseInfoTest method beforeMethod.
@Before
public void beforeMethod() {
headers = new DefaultHttpHeaders();
responseInfoMock = mock(ResponseInfo.class);
doReturn(headers).when(responseInfoMock).getHeaders();
wrapper = new HttpServletResponseWrapperForResponseInfo<>(responseInfoMock);
}
use of io.netty.handler.codec.http.DefaultHttpHeaders in project riposte by Nike-Inc.
the class RequestInfoImpl method dummyInstanceForUnknownRequests.
/**
* Creates a new RequestInfo that represents unknown requests. Usually only needed in error situations. The URI,
* query params, and headers will be tagged with {@link #NONE_OR_UNKNOWN_TAG} to indicate that the request was
* unknown.
*/
public static RequestInfoImpl<?> dummyInstanceForUnknownRequests() {
HttpHeaders headers = new DefaultHttpHeaders().set(NONE_OR_UNKNOWN_TAG, "true");
QueryStringDecoder queryParams = new QueryStringDecoder("/?" + NONE_OR_UNKNOWN_TAG + "=true");
return new RequestInfoImpl(NONE_OR_UNKNOWN_TAG, null, headers, null, queryParams, null, null, null, null, false, true, false);
}
Aggregations