Package io.netty.handler.codec.http

Examples of io.netty.handler.codec.http.DefaultFullHttpResponse.headers()


     * @param version the {@link HttpVersion} that the response should have.
     * @param status the status of the HTTP response
     */
    public static FullHttpResponse responseWithoutContent(final HttpVersion version, final HttpResponseStatus status) {
        final FullHttpResponse response = new DefaultFullHttpResponse(version, status);
        response.headers().set(CONTENT_LENGTH, 0);
        return response;
    }

    /**
     * Creates FullHttpResponse with a response body.
View Full Code Here


    public static FullHttpResponse response(final HttpRequest request) {
        final FullHttpResponse response = new DefaultFullHttpResponse(
                request.getProtocolVersion(),
                OK,
                CONTENT.duplicate());
        response.headers().set(CONTENT_TYPE, Transports.CONTENT_TYPE_PLAIN);
        return response;
    }

}
View Full Code Here

        if (msg instanceof Frame) {
            final Frame frame = (Frame) msg;
            final ByteBuf content = Transports.wrapWithLN(frame.content());
            frame.release();
            final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), OK, content);
            response.headers().set(CONTENT_TYPE, CONTENT_TYPE_JAVASCRIPT);
            response.headers().set(CONTENT_LENGTH, content.readableBytes());
            response.headers().set(CONNECTION, CLOSE);
            Transports.setDefaultHeaders(response, config, request);
            Transports.writeResponse(ctx, promise, response);
        } else {
View Full Code Here

            final Frame frame = (Frame) msg;
            final ByteBuf content = Transports.wrapWithLN(frame.content());
            frame.release();
            final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), OK, content);
            response.headers().set(CONTENT_TYPE, CONTENT_TYPE_JAVASCRIPT);
            response.headers().set(CONTENT_LENGTH, content.readableBytes());
            response.headers().set(CONNECTION, CLOSE);
            Transports.setDefaultHeaders(response, config, request);
            Transports.writeResponse(ctx, promise, response);
        } else {
            ctx.writeAndFlush(ReferenceCountUtil.retain(msg), promise);
View Full Code Here

            final ByteBuf content = Transports.wrapWithLN(frame.content());
            frame.release();
            final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), OK, content);
            response.headers().set(CONTENT_TYPE, CONTENT_TYPE_JAVASCRIPT);
            response.headers().set(CONTENT_LENGTH, content.readableBytes());
            response.headers().set(CONNECTION, CLOSE);
            Transports.setDefaultHeaders(response, config, request);
            Transports.writeResponse(ctx, promise, response);
        } else {
            ctx.writeAndFlush(ReferenceCountUtil.retain(msg), promise);
        }
View Full Code Here

        }

        @Override
        public FullHttpResponse copy() {
            DefaultFullHttpResponse copy = new DefaultFullHttpResponse(getProtocolVersion(), getStatus(), content.copy());
            copy.headers().set(headers());
            copy.trailingHeaders().set(trailingHeaders());
            return copy;
        }

        @Override
View Full Code Here

        @Override
        public HttpContent duplicate() {
            DefaultFullHttpResponse dup = new DefaultFullHttpResponse(getProtocolVersion(), getStatus(),
                                                                      content.duplicate());
            dup.headers().set(headers());
            dup.trailingHeaders().set(trailingHeaders());
            return dup;
        }

        @Override
View Full Code Here

            byte[] data = IOUtils.toByteArray(is);
            ByteBuf content = Unpooled.wrappedBuffer(data);

            FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content);

            res.headers().set(CONTENT_TYPE, "application/javascript");
            setContentLength(res, content.readableBytes());

            sendHttpResponse(ctx, req, res);
            return;
        }
View Full Code Here

    private static final Pattern ALLOWED_FILE_NAME = Pattern.compile("[A-Za-z0-9][-_A-Za-z0-9\\.]*");

    private static void sendListing(ChannelHandlerContext ctx, File dir) {
        FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK);
        response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");

        StringBuilder buf = new StringBuilder();
        String dirPath = dir.getPath();

        buf.append("<!DOCTYPE html>\r\n");
View Full Code Here

        ctx.write(response).addListener(ChannelFutureListener.CLOSE);
    }

    private static void sendRedirect(ChannelHandlerContext ctx, String newUri) {
        FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, FOUND);
        response.headers().set(LOCATION, newUri);

        // Close the connection as soon as the error message is sent.
        ctx.write(response).addListener(ChannelFutureListener.CLOSE);
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.