Package io.netty.handler.codec.http

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


            FullHttpRequest req = (FullHttpRequest) msg;
            Channel channel = ctx.channel();
            QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());
            if (!configuration.isAllowCustomRequests()
                    && !queryDecoder.path().startsWith(connectPath)) {
                HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
                ChannelFuture f = channel.write(res);
                f.addListener(ChannelFutureListener.CLOSE);
                req.release();
                log.warn("Blocked wrong request! url: {}, ip: {}", queryDecoder.path(), channel.remoteAddress());
                return;
View Full Code Here


            handshake(sessionId);
            HandshakeMessage message = new HandshakeMessage(sessionId);
            configuration.getStoreFactory().getPubSubStore().publish(PubSubStore.HANDSHAKE, message);
            log.debug("Handshake authorized for sessionId: {}", sessionId);
        } else {
            HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN);
            ChannelFuture f = channel.write(res);
            f.addListener(ChannelFutureListener.CLOSE);

            log.debug("Handshake unauthorized");
        }
View Full Code Here

                if (is == null) {
                    sendError(ctx, NOT_FOUND);
                    return;
                }
                // create ok response
                HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.OK);
                // set Content-Length header
                long fileSize = getHeaderFieldLong(fileUrl, "content-length");
                setContentLength(res, fileSize);
                // set Content-Type header
                setContentTypeHeader(res, fileUrl);
View Full Code Here

    /*
     * Sends a Not Modified response to the client
     *
     * */
    private void sendNotModified(ChannelHandlerContext ctx) {
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.NOT_MODIFIED);
        setDateHeader(response);

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

     *
     * @param ctx
     * @param status
     */
    private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
        HttpHeaders.setHeader(response, CONTENT_TYPE, "text/plain; charset=UTF-8");
        ByteBuf content = Unpooled.copiedBuffer( "Failure: " + status.toString() + "\r\n", CharsetUtil.UTF_8);

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

        final ByteBuf content = Unpooled.buffer();
        content.writeBytes("503 Service Unavailable - Server Too Busy"
            .getBytes());

        final HttpResponse response =
            new DefaultHttpResponse(HttpVersion.HTTP_1_1,
                HttpResponseStatus.SERVICE_UNAVAILABLE);
        response.setContent(content);
        response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
            content.readableBytes());

        context.write(response)
            .addListener(ChannelFutureListener.CLOSE);
View Full Code Here

  }

  private void handleHttpRequest(final ChannelHandlerContext ctx, final HttpRequest req) throws Exception {
    // Allow only GET methods.
    if (req.getMethod() != GET) {
      sendHttpResponse(ctx, req, new DefaultHttpResponse(HTTP_1_1, FORBIDDEN));
      return;
    }

    // Handshake
    final WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
View Full Code Here

  }

  private void handleHttpRequest(ChannelHandlerContext ctx, HttpRequest req) throws Exception {
    // Allow only GET methods.
    if (req.getMethod() != GET) {
      sendHttpResponse(ctx, req, new DefaultHttpResponse(HTTP_1_1, FORBIDDEN));
      return;
    }

    // Handshake
    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
View Full Code Here

        if (original instanceof DefaultFullHttpResponse) {
            ByteBuf content = ((DefaultFullHttpResponse) original).content();
            copy = new DefaultFullHttpResponse(original.getProtocolVersion(),
                    original.getStatus(), content);
        } else {
            copy = new DefaultHttpResponse(original.getProtocolVersion(),
                    original.getStatus());
        }
        final Collection<String> headerNames = original.headers().names();
        for (final String name : headerNames) {
            final List<String> values = original.headers().getAll(name);
View Full Code Here

        HttpResponseStatus status = SpdyHeaders.getStatus(responseFrame);
        HttpVersion version = SpdyHeaders.getVersion(responseFrame);
        SpdyHeaders.removeStatus(responseFrame);
        SpdyHeaders.removeVersion(responseFrame);

        HttpResponse httpResponse = new DefaultHttpResponse(version, status);
        for (Map.Entry<String, String> e: responseFrame.getHeaders()) {
            httpResponse.addHeader(e.getKey(), e.getValue());
        }

        // Chunked encoding is no longer valid
        List<String> encodings = httpResponse.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
        encodings.remove(HttpHeaders.Values.CHUNKED);
        if (encodings.isEmpty()) {
            httpResponse.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
        } else {
            httpResponse.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, encodings);
        }
        httpResponse.removeHeader(HttpHeaders.Names.TRAILER);

        // The Connection and Keep-Alive headers are no longer valid
        HttpHeaders.setKeepAlive(httpResponse, true);

        return httpResponse;
View Full Code Here

TOP

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

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.