Package io.netty.handler.codec.http

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


    }

    private static void handlePreflight(final ChannelHandlerContext ctx, final CorsMetadata md,
                                        final HttpRequest request) {
        final HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), NO_CONTENT);
        final HttpHeaders headers = response.headers();
        headers.set(CONTENT_TYPE, Transports.CONTENT_TYPE_PLAIN);
        headers.set(CACHE_CONTROL, "max-age=31536000, public");
        headers.set(ACCESS_CONTROL_ALLOW_ORIGIN, md.origin());
        headers.set(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
        headers.set(ACCESS_CONTROL_MAX_AGE, "31536000");
View Full Code Here


    protected HttpResponse createResponse(final String contentType) {
        final HttpVersion version = request.getProtocolVersion();
        final HttpResponse response = new DefaultHttpResponse(version, HttpResponseStatus.OK);
        if (request.getProtocolVersion().equals(HttpVersion.HTTP_1_1)) {
            response.headers().set(TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
        }
        response.headers().set(CONTENT_TYPE, contentType);
        Transports.setDefaultHeaders(response, config);
        return response;
    }
View Full Code Here

        final HttpVersion version = request.getProtocolVersion();
        final HttpResponse response = new DefaultHttpResponse(version, HttpResponseStatus.OK);
        if (request.getProtocolVersion().equals(HttpVersion.HTTP_1_1)) {
            response.headers().set(TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
        }
        response.headers().set(CONTENT_TYPE, contentType);
        Transports.setDefaultHeaders(response, config);
        return response;
    }

}
View Full Code Here

        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
        setContentLength(response, fileLength);
        setContentTypeHeader(response, file);
        setDateAndCacheHeaders(response, file);
        if (isKeepAlive(request)) {
            response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
        }

        // Write the initial line and the header.
        ctx.write(response);
View Full Code Here

     */
    public static void sendUnsupportedWebSocketVersionResponse(Channel channel) {
        HttpResponse res = new DefaultHttpResponse(
                HttpVersion.HTTP_1_1,
                HttpResponseStatus.UPGRADE_REQUIRED);
        res.headers().set(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
        channel.write(res);
    }
}
View Full Code Here

        String cookie1Value = "ID=a95756377b78e75e:FF=0:TM=1392709628:LM=1392709628:S=a5mOVvTB7DBkexgi";
        String cookie1Domain = ".google.com";
        String cookie1Path = "/";
        String cookie1Header = cookie1Name + '=' + cookie1Value
                               + "; expires=Thu, 18-Feb-2016 07:47:08 GMT; path=" + cookie1Path + "; domain=" + cookie1Domain;
        nettyResponse.headers().add(HttpHeaders.Names.SET_COOKIE, cookie1Header);
        HttpClientResponse<ByteBuf> response = new HttpClientResponse<ByteBuf>(nettyResponse, UnicastContentSubject.<ByteBuf>createWithoutNoSubscriptionTimeout());
        Map<String,Set<Cookie>> cookies = response.getCookies();
        Assert.assertNotNull("Cookies are null.", cookies);
        Assert.assertEquals("Cookies are empty.", 1, cookies.size());
        Set<Cookie> cookies1 = cookies.get(cookie1Name);
View Full Code Here

                new HttpServerResponse<ByteBuf>(new NoOpChannelHandlerContext().channel(), nettyResponse,
                                                new MetricEventsSubject<HttpServerMetricsEvent<?>>());
        String cookieName = "name";
        String cookieValue = "value";
        response.addCookie(new DefaultCookie(cookieName, cookieValue));
        String cookieHeader = nettyResponse.headers().get(HttpHeaders.Names.SET_COOKIE);
        Assert.assertNotNull("Cookie header not found.", cookieHeader);
        Set<Cookie> decode = CookieDecoder.decode(cookieHeader);
        Assert.assertNotNull("Decoded cookie not found.", decode);
        Assert.assertEquals("Unexpected number of decoded cookie not found.", 1, decode.size());
        Cookie cookie = decode.iterator().next();
View Full Code Here

        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);

        holder.handler.write(holder.ctx, response, holder.ctx.newPromise());

        ContextKeySupplier supplier = new HttpContextKeySupplier(response.headers());
        ContextsContainer containerToRead = new ContextsContainerImpl(supplier);
        Assert.assertEquals("Bi-directional context not written in response.", ctx2, containerToRead.getContext(
                ctx2Name));
    }
View Full Code Here

        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
        HttpHeaders.setContentLength(response, fileLength);
        setContentTypeHeader(response, file);
        setDateAndCacheHeaders(response, file);
        if (HttpHeaders.isKeepAlive(request)) {
            response.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
        }

        // Write the initial line and the header.
        ctx.write(response);
View Full Code Here

    }

    private void sendMessage(HttpMessage msg, Channel channel, ByteBuf out, String type) {
        HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.OK);

        res.headers().add(CONTENT_TYPE, type).add("Set-Cookie", "io=" + msg.getSessionId())
                .add(CONNECTION, KEEP_ALIVE);

        addOriginHeaders(channel, res);
        HttpHeaders.setContentLength(res, out.readableBytes());
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.