use of io.netty.handler.codec.http.DefaultFullHttpResponse in project tesla by linking12.
the class HttpRequestFilter method createResponse.
protected HttpResponse createResponse(HttpResponseStatus httpResponseStatus, HttpRequest originalRequest) {
HttpHeaders httpHeaders = new DefaultHttpHeaders();
httpHeaders.add("Transfer-Encoding", "chunked");
HttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, httpResponseStatus);
List<String> originHeader = FilterUtil.getHeaderValues(originalRequest, "Origin");
if (originHeader.size() > 0) {
httpHeaders.set("Access-Control-Allow-Credentials", "true");
httpHeaders.set("Access-Control-Allow-Origin", originHeader.get(0));
}
httpResponse.headers().add(httpHeaders);
return httpResponse;
}
use of io.netty.handler.codec.http.DefaultFullHttpResponse in project cxf by apache.
the class NettyHttpServletHandler method handleHttpServletRequest.
protected void handleHttpServletRequest(ChannelHandlerContext ctx, HttpRequest request, NettyHttpContextHandler nettyHttpContextHandler) throws Exception {
interceptOnRequestReceived(ctx, request);
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
NettyServletResponse nettyServletResponse = buildHttpServletResponse(response);
NettyHttpServletRequest nettyServletRequest = buildHttpServletRequest(request, nettyHttpContextHandler.getContextPath(), ctx);
nettyHttpContextHandler.handle(nettyServletRequest.getRequestURI(), nettyServletRequest, nettyServletResponse);
interceptOnRequestSuccessed(ctx, response);
nettyServletResponse.getWriter().flush();
boolean keepAlive = HttpHeaders.isKeepAlive(request);
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.headers().set(Names.CONTENT_LENGTH, response.content().readableBytes());
// Add keep alive header as per:
// -
// http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
response.headers().set(Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
}
// write response...
ChannelFuture future = ctx.write(response);
if (!keepAlive) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
use of io.netty.handler.codec.http.DefaultFullHttpResponse in project cxf by apache.
the class NettyHttpServletHandler method sendError.
private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
ByteBuf content = Unpooled.copiedBuffer("Failure: " + status.toString() + "\r\n", CharsetUtil.UTF_8);
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, content);
response.headers().set(Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
}
use of io.netty.handler.codec.http.DefaultFullHttpResponse in project janusgraph by JanusGraph.
the class HttpHMACAuthenticationHandler method replyWithToken.
private void replyWithToken(final ChannelHandlerContext ctx, final Object msg, final String token) {
final String json = "{\"token\": \"" + token + "\"}";
final byte[] jsonBytes = json.getBytes();
final FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(jsonBytes));
response.headers().set(CONTENT_TYPE, "application/json");
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
ReferenceCountUtil.release(msg);
}
Aggregations