Package io.netty.handler.codec.http

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


        if (!PATH_PATTERN.matcher(path).matches()) {
            return createResponse(request, NOT_FOUND, copiedBuffer("Not found", UTF_8));
        }

        if (request.headers().contains(HttpHeaders.Names.IF_NONE_MATCH)) {
            final FullHttpResponse response = createResponse(request, NOT_MODIFIED);
            response.headers().set(HttpHeaders.Names.SET_COOKIE, "JSESSIONID=dummy; path=/");
            return response;
        } else {
            final String content = createContent(config.sockJsUrl());
            final FullHttpResponse response = createResponse(request, OK, copiedBuffer(content, UTF_8));
            response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8");
            response.headers().set(HttpHeaders.Names.CACHE_CONTROL, "max-age=31536000, public");
            response.headers().set(HttpHeaders.Names.EXPIRES, generateExpires());
            final String etag = '\"' + generateMd5(content) + '\"';
            response.headers().set(HttpHeaders.Names.ETAG, etag);
            return response;
        }
    }
View Full Code Here


            final HttpVersion version,
            final HttpResponseStatus status,
            final String contentType,
            final String content,
            final ChannelPromise promise) {
        final FullHttpResponse response = responseWithContent(version, status, contentType, content);
        writeResponse(ctx, response);
    }
View Full Code Here

    public static void respond(final ChannelHandlerContext ctx,
            final HttpVersion version,
            final HttpResponseStatus status,
            final String contentType,
            final String content) {
        final FullHttpResponse response = responseWithContent(version, status, contentType, content);
        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

        super(config);
    }

    @Override
    public void respond(final ChannelHandlerContext ctx, final FullHttpRequest request) throws Exception {
        final FullHttpResponse response = responseWithContent(request.getProtocolVersion(), OK, CONTENT_TYPE_PLAIN, "ok");
        logger.info("Responding=" + response.getStatus() + ", request.uri=" + request.getUri());
        setDefaultHeaders(response, config);
        if (ctx.channel().isActive() && ctx.channel().isRegistered()) {
            ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
        }
    }
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

    protected void respond(final ChannelHandlerContext ctx,
            final HttpVersion httpVersion,
            final HttpResponseStatus status,
            final String message) {
        final FullHttpResponse response = responseWithContent(httpVersion, status, CONTENT_TYPE_PLAIN, message);
        Transports.setDefaultHeaders(response, config);
        if (ctx.channel().isActive() && ctx.channel().isRegistered()) {
            ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
        }
    }
View Full Code Here

            ctx.write(ReferenceCountUtil.retain(msg), promise);
        }
    }

    private void respondCallbackRequired(final ChannelHandlerContext ctx) {
        final FullHttpResponse response = Transports.responseWithContent(request.getProtocolVersion(),
                INTERNAL_SERVER_ERROR,
                Transports.CONTENT_TYPE_PLAIN,
                "\"callback\" parameter required");
        Transports.setNoCacheHeaders(response);
        Transports.writeResponse(ctx, response);
View Full Code Here

        buffer.release();

        final DefaultHttpContent openResponse = ch.readOutbound();
        assertThat(openResponse.content().toString(UTF_8), equalTo("o\n"));

        final FullHttpResponse validSend = xhrSendRequest(sessionUrl, "[\"x\"]", serviceFactory);
        assertThat(validSend.getStatus(), is(HttpResponseStatus.NO_CONTENT));

        final DefaultHttpContent chunk = ch.readOutbound();
        assertThat(chunk.content().toString(UTF_8), equalTo("a[\"x\"]\n"));
    }
View Full Code Here

TOP

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

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.