Package io.netty.handler.codec.http

Examples of io.netty.handler.codec.http.DefaultFullHttpResponse


        // Hixie 75 does not contain these headers while Hixie 76 does
        boolean isHixie76 = req.headers().contains(SEC_WEBSOCKET_KEY1) && req.headers().contains(SEC_WEBSOCKET_KEY2);

        // Create the WebSocket handshake response.
        FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
                isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
        if (headers != null) {
            res.headers().add(headers);
        }

        res.headers().add(Names.UPGRADE, WEBSOCKET);
        res.headers().add(CONNECTION, Values.UPGRADE);

        // Fill in the headers and contents depending on handshake getMethod.
        if (isHixie76) {
            // New handshake getMethod with a challenge:
            res.headers().add(SEC_WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
            res.headers().add(SEC_WEBSOCKET_LOCATION, uri());
            String subprotocols = req.headers().get(SEC_WEBSOCKET_PROTOCOL);
            if (subprotocols != null) {
                String selectedSubprotocol = selectSubprotocol(subprotocols);
                if (selectedSubprotocol == null) {
                    throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
                } else {
                    res.headers().add(SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
                }
            }

            // Calculate the answer of the challenge.
            key1 = req.headers().get(SEC_WEBSOCKET_KEY1);
            key2 = req.headers().get(SEC_WEBSOCKET_KEY2);
        } else {
            // Old Hixie 75 handshake getMethod with no challenge:
            res.headers().add(WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
            res.headers().add(WEBSOCKET_LOCATION, uri());
            String protocol = req.headers().get(WEBSOCKET_PROTOCOL);
            if (protocol != null) {
                res.headers().add(WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
            }
        }
        return res;
    }
View Full Code Here


            throws Exception {
        if (msg instanceof Frame) {
            final Frame frame = (Frame) msg;
            final ByteBuf content = wrapWithFunction(frame.content(), ctx);
            frame.release();
            final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), OK, content);
            response.headers().set(CONTENT_TYPE, Transports.CONTENT_TYPE_JAVASCRIPT);
            response.headers().set(CONTENT_LENGTH, content.readableBytes());
            response.headers().set(CONNECTION, HttpHeaders.Values.CLOSE);
            Transports.setNoCacheHeaders(response);
            Transports.setSessionIdCookie(response, config, request);
            ctx.writeAndFlush(response, promise);
        } else {
            ctx.write(ReferenceCountUtil.retain(msg), promise);
View Full Code Here

    private static void respond(final ChannelHandlerContext ctx,
                                final HttpVersion httpVersion,
                                final HttpResponseStatus status,
                                final String message) throws Exception {
        final FullHttpResponse response = new DefaultFullHttpResponse(httpVersion, status);
        Transports.writeContent(response, message, Transports.CONTENT_TYPE_JAVASCRIPT);
        Transports.writeResponse(ctx, response);
    }
View Full Code Here

     *
     * @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;
    }
View Full Code Here

     * @param contentType the value for the 'Content-Type' HTTP response header.
     * @param content the content that will become the body of the HTTP response.
     */
    public static FullHttpResponse responseWithContent(final HttpVersion version, final HttpResponseStatus status,
            final String contentType, final String content) {
        final FullHttpResponse response = new DefaultFullHttpResponse(version, status);
        writeContent(response, content, contentType);
        return response;
    }
View Full Code Here

        }
        return path.isEmpty() || "/".equals(path);
    }

    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

        }
        return session;
    }

    private static void writeNotFoundResponse(final HttpRequest request, final ChannelHandlerContext ctx) {
        final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), NOT_FOUND,
                Unpooled.copiedBuffer("Not found", CharsetUtil.UTF_8));
        writeResponse(ctx.channel(), request, response);
    }
View Full Code Here

    private static String generateExpires() {
        return DATE_FORMAT.get().format(new Date(System.currentTimeMillis() + ONE_YEAR));
    }

    private static FullHttpResponse createResponse(final HttpRequest request, final HttpResponseStatus status) {
        return new DefaultFullHttpResponse(request.getProtocolVersion(), status);
    }
View Full Code Here

        return new DefaultFullHttpResponse(request.getProtocolVersion(), status);
    }

    private static FullHttpResponse createResponse(final HttpRequest request, final HttpResponseStatus status,
            final ByteBuf content) {
        return new DefaultFullHttpResponse(request.getProtocolVersion(), status, content);
    }
View Full Code Here

            throws Exception {
        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 {
            ctx.writeAndFlush(ReferenceCountUtil.retain(msg), promise);
        }
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.http.DefaultFullHttpResponse

Copyright © 2018 www.massapicom. 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.