Package io.netty.handler.codec.http

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


    }

    private static HttpHeaders headersFromInfo() throws Exception {
        final SockJsConfig config = SockJsConfig.withPrefix("/simplepush").disableWebSocket().build();
        final FullHttpResponse response = Info.response(config, createHttpRequest("/simplepush"));
        final HttpHeaders headers = response.headers();
        response.release();
        return headers;
    }
View Full Code Here


    private SockJsTestUtil() {
    }

    public static void verifyDefaultResponseHeaders(final HttpResponse response, final String contentType) {
        final HttpHeaders headers = response.headers();
        assertThat(headers.get(HttpHeaders.Names.CONTENT_TYPE), equalTo(contentType));
        verifyNoCacheHeaders(response);
        assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN), equalTo("*"));
        assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS), equalTo("true"));
        assertThat(headers.get(HttpHeaders.Names.SET_COOKIE), is(notNullValue()));
    }
View Full Code Here

    public static void verifyContentType(final HttpResponse response, final String contentType) {
        assertThat(response.headers().get(HttpHeaders.Names.CONTENT_TYPE), equalTo(contentType));
    }

    public static void verifyNoCacheHeaders(final HttpResponse response) {
        final HttpHeaders headers = response.headers();
        assertThat(headers.get(HttpHeaders.Names.CACHE_CONTROL), containsString("no-store"));
        assertThat(headers.get(HttpHeaders.Names.CACHE_CONTROL), containsString("no-cache"));
        assertThat(headers.get(HttpHeaders.Names.CACHE_CONTROL), containsString("must-revalidate"));
        assertThat(headers.get(HttpHeaders.Names.CACHE_CONTROL), containsString("max-age=0"));
    }
View Full Code Here

        assertThat(headers.get(HttpHeaders.Names.CACHE_CONTROL), containsString("must-revalidate"));
        assertThat(headers.get(HttpHeaders.Names.CACHE_CONTROL), containsString("max-age=0"));
    }

    public static void assertCORSHeaders(final HttpResponse response, final String origin) {
        final HttpHeaders headers = response.headers();
        assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN), equalTo(origin));
        assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS), equalTo("true"));
    }
View Full Code Here

        encoder.addParam("thirdinfo", "third value\r\ntest second line\r\n\r\nnew line\r\n");
        encoder.addParam("Send", "Send");

        URI uriGet = new URI(encoder.toString());
        HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uriGet.toASCIIString());
        HttpHeaders headers = request.headers();
        headers.set(HttpHeaders.Names.HOST, host);
        headers.set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
        headers.set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP + ',' + HttpHeaders.Values.DEFLATE);

        headers.set(HttpHeaders.Names.ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
        headers.set(HttpHeaders.Names.ACCEPT_LANGUAGE, "fr");
        headers.set(HttpHeaders.Names.REFERER, uriSimple.toString());
        headers.set(HttpHeaders.Names.USER_AGENT, "Netty Simple Http Client side");
        headers.set(HttpHeaders.Names.ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

        //connection will not close but needed
        // headers.set("Connection","keep-alive");
        // headers.set("Keep-Alive","300");

        headers.set(
                HttpHeaders.Names.COOKIE, ClientCookieEncoder.encode(
                        new DefaultCookie("my-cookie", "foo"),
                        new DefaultCookie("another-cookie", "bar"))
        );

        // send request
        List<Entry<String, String>> entries = headers.entries();
        channel.writeAndFlush(request);

        // Wait for the server to close the connection.
        channel.closeFuture().sync();

View Full Code Here

            } else {
                // We must allow 401 handling again.
                future.getAndSetAuth(false);

                HttpHeaders responseHeaders = response.headers();
                String location = responseHeaders.get(HttpHeaders.Names.LOCATION);
                Uri uri = Uri.create(future.getUri(), location);

                if (!uri.equals(future.getUri())) {
                    final RequestBuilder requestBuilder = new RequestBuilder(future.getRequest());

                    if (!config.isRemoveQueryParamOnRedirect())
                        requestBuilder.addQueryParams(future.getRequest().getQueryParams());

                    // if we are to strictly handle 302, we should keep the original method (which browsers don't)
                    // 303 must force GET
                    if ((statusCode == FOUND.code() && !config.isStrict302Handling()) || statusCode == SEE_OTHER.code())
                        requestBuilder.setMethod("GET");

                    // in case of a redirect from HTTP to HTTPS, future attributes might change
                    final boolean initialConnectionKeepAlive = future.isKeepAlive();
                    final String initialPoolKey = channelManager.getPartitionId(future);

                    future.setUri(uri);
                    String newUrl = uri.toUrl();
                    if (request.getUri().getScheme().startsWith(WEBSOCKET)) {
                        newUrl = newUrl.replaceFirst(HTTP, WEBSOCKET);
                    }

                    logger.debug("Redirecting to {}", newUrl);

                    for (String cookieStr : responseHeaders.getAll(HttpHeaders.Names.SET_COOKIE)) {
                        Cookie c = CookieDecoder.decode(cookieStr, timeConverter);
                        if (c != null)
                            requestBuilder.addOrReplaceCookie(c);
                    }
View Full Code Here

            boolean reclaimCache) throws IOException {

        boolean useSSl = isSecure(uri) && !useProxy;

        // some headers are only set when performing the first request
        HttpHeaders headers = future.getNettyRequest().getHttpRequest().headers();
        Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();
        HttpMethod method = future.getNettyRequest().getHttpRequest().getMethod();
        requestFactory.addAuthorizationHeader(headers, requestFactory.firstRequestOnlyAuthorizationHeader(request, uri, proxy, realm));
        requestFactory.setProxyAuthorizationHeader(headers, requestFactory.firstRequestOnlyProxyAuthorizationHeader(request, proxy, method));
View Full Code Here

        } else {
            httpRequest = new DefaultHttpRequest(httpVersion, method, requestUri);
            nettyRequest = new NettyRequest(httpRequest, body);
        }

        HttpHeaders headers = httpRequest.headers();

        if (method != HttpMethod.CONNECT) {
            // assign headers as configured on request
            for (Entry<String, List<String>> header : request.getHeaders()) {
                headers.set(header.getKey(), header.getValue());
            }

            if (isNonEmpty(request.getCookies()))
                headers.set(HttpHeaders.Names.COOKIE, CookieEncoder.encode(request.getCookies()));

            if (config.isCompressionEnforced() && !headers.contains(HttpHeaders.Names.ACCEPT_ENCODING))
                headers.set(HttpHeaders.Names.ACCEPT_ENCODING, GZIP_DEFLATE);
        }

        if (body != null) {
            if (body.getContentLength() < 0)
                headers.set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
            else
                headers.set(HttpHeaders.Names.CONTENT_LENGTH, body.getContentLength());

            if (body.getContentType() != null)
                headers.set(HttpHeaders.Names.CONTENT_TYPE, body.getContentType());
        }

        // connection header and friends
        boolean webSocket = isWebSocket(uri.getScheme());
        if (method != HttpMethod.CONNECT && webSocket) {
            headers.set(HttpHeaders.Names.UPGRADE, HttpHeaders.Values.WEBSOCKET)//
            .set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.UPGRADE)//
            .set(HttpHeaders.Names.ORIGIN, "http://" + uri.getHost() + ":" + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort()))//
            .set(HttpHeaders.Names.SEC_WEBSOCKET_KEY, getKey())//
            .set(HttpHeaders.Names.SEC_WEBSOCKET_VERSION, "13");

        } else if (!headers.contains(HttpHeaders.Names.CONNECTION)) {
            headers.set(HttpHeaders.Names.CONNECTION, keepAliveHeaderValue(config));
        }

        if (!headers.contains(HttpHeaders.Names.HOST))
            headers.set(HttpHeaders.Names.HOST,  hostHeader(request, uri));

        Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();

        // don't override authorization but append
        addAuthorizationHeader(headers, systematicAuthorizationHeader(request, uri, proxyServer, realm));

        setProxyAuthorizationHeader(headers, systematicProxyAuthorizationHeader(request, proxyServer, method));

        // Add default accept headers
        if (!headers.contains(HttpHeaders.Names.ACCEPT))
            headers.set(HttpHeaders.Names.ACCEPT, "*/*");

        // Add default user agent
        if (!headers.contains(HttpHeaders.Names.USER_AGENT) && config.getUserAgent() != null)
            headers.set(HttpHeaders.Names.USER_AGENT, config.getUserAgent());

        return nettyRequest;
    }
View Full Code Here

                boolean last = chunk instanceof LastHttpContent;

                // Netty 4: the last chunk is not empty
                if (last) {
                    LastHttpContent lastChunk = (LastHttpContent) chunk;
                    HttpHeaders trailingHeaders = lastChunk.trailingHeaders();
                    if (!trailingHeaders.isEmpty()) {
                        NettyResponseHeaders responseHeaders = new NettyResponseHeaders(future.getHttpHeaders(), trailingHeaders);
                        interrupt = handler.onHeadersReceived(responseHeaders) != STATE.CONTINUE;
                    }
                }
View Full Code Here

            return this;
        }

        private HttpHeaders waitForHeaders(String lookingFor) throws InterruptedException {
            await(HeadersReceived);
            HttpHeaders h = getHeaders();
            if (h == null) {
                await(Closed);
                h = getHeaders();
            } else {
                String s = h.get(lookingFor);
                if (s == null) {
                    await(Closed);
                }
            }
            return h;
View Full Code Here

TOP

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

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.