Package io.netty.handler.codec.http

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


        final String text = "some data";
        final ByteBuf content = Unpooled.copiedBuffer(text.getBytes());
        final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
                "/some/path/resource2", content, true);
        try {
            HttpHeaders httpHeaders = request.headers();
            httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
            HttpHeaders trailingHeaders = request.trailingHeaders();
            trailingHeaders.set("Foo", "goo");
            trailingHeaders.set("fOo2", "goo2");
            trailingHeaders.add("foO2", "goo3");
            final Http2Headers http2Headers =
                    new DefaultHttp2Headers().method(as("GET")).path(
                            as("/some/path/resource2"));
            final Http2Headers http2Headers2 =
                    new DefaultHttp2Headers().set(as("foo"), as("goo"))
View Full Code Here


        final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT,
                "/some/path/resource", content, true);
        final FullHttpMessage request2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT,
                "/some/path/resource2", content2, true);
        try {
            HttpHeaders httpHeaders = request.headers();
            httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
            HttpHeaders httpHeaders2 = request2.headers();
            httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
            httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3);
            httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 123);
            httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());
            final Http2Headers http2Headers = new DefaultHttp2Headers().method(as("PUT"))
                    .path(as("/some/path/resource"));
            final Http2Headers http2Headers2 = new DefaultHttp2Headers().method(as("PUT"))
                    .path(as("/some/path/resource2"));
            runInChannel(clientChannel, new Http2Runnable() {
View Full Code Here

        final FullHttpMessage request2 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT,
                "/some/path/resource2", content2, true);
        final FullHttpMessage request3 = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpUtil.OUT_OF_MESSAGE_SEQUENCE_METHOD, HttpUtil.OUT_OF_MESSAGE_SEQUENCE_PATH, true);
        try {
            HttpHeaders httpHeaders = request.headers();
            httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
            HttpHeaders httpHeaders2 = request2.headers();
            httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
            httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());
            final Http2Headers http2Headers = new DefaultHttp2Headers().method(as("PUT"))
                    .path(as("/some/path/resource"));
            final Http2Headers http2Headers2 = new DefaultHttp2Headers().method(as("PUT"))
                    .path(as("/some/path/resource2"));
            HttpHeaders httpHeaders3 = request3.headers();
            httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
            httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_DEPENDENCY_ID.text(), 3);
            httpHeaders3.setInt(HttpUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), 222);
            httpHeaders3.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
            runInChannel(clientChannel, new Http2Runnable() {
                @Override
                public void run() {
                    frameWriter.writeHeaders(ctxClient(), 3, http2Headers, 0, false, newPromiseClient());
                    frameWriter.writeHeaders(ctxClient(), 5, http2Headers2, 0, false, newPromiseClient());
View Full Code Here

        final FullHttpMessage response2 = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CREATED,
                content2, true);
        final FullHttpMessage request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.GET, "/push/test", true);
        try {
            HttpHeaders httpHeaders = response.headers();
            httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
            HttpHeaders httpHeaders2 = response2.headers();
            httpHeaders2.set(HttpUtil.ExtensionHeaderNames.SCHEME.text(), "https");
            httpHeaders2.set(HttpUtil.ExtensionHeaderNames.AUTHORITY.text(), "example.org");
            httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 5);
            httpHeaders2.setInt(HttpUtil.ExtensionHeaderNames.STREAM_PROMISE_ID.text(), 3);
            httpHeaders2.setInt(HttpHeaderNames.CONTENT_LENGTH, text2.length());

            httpHeaders = request.headers();
            httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
            final Http2Headers http2Headers3 = new DefaultHttp2Headers().method(as("GET"))
View Full Code Here

    @Test
    public void serverResponseHeaderInformational() throws Exception {
        final FullHttpMessage request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "/info/test",
                true);
        HttpHeaders httpHeaders = request.headers();
        httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
        httpHeaders.set(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE);
        httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
        final Http2Headers http2Headers =
                new DefaultHttp2Headers()
                        .method(as("PUT"))
                        .path(as("/info/test"))
                        .set(as(HttpHeaderNames.EXPECT.toString()), as(HttpHeaderValues.CONTINUE.toString()));
        final FullHttpMessage response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE);
        final String text = "a big payload";
        final ByteBuf payload = Unpooled.copiedBuffer(text.getBytes());
        final FullHttpMessage request2 = request.copy(payload);
        final FullHttpMessage response2 = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);

        try {
            runInChannel(clientChannel, new Http2Runnable() {
                @Override
                public void run() {
                    frameWriter.writeHeaders(ctxClient(), 3, http2Headers, 0, false, newPromiseClient());
                    ctxClient().flush();
                }
            });
            awaitRequests();
            ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
            verify(serverListener).messageReceived(requestCaptor.capture());
            capturedRequests = requestCaptor.getAllValues();
            assertEquals(request, capturedRequests.get(0));
            cleanupCapturedRequests();
            reset(serverListener);

            httpHeaders = response.headers();
            httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
            final Http2Headers http2HeadersResponse = new DefaultHttp2Headers().status(as("100"));
            runInChannel(serverConnectedChannel, new Http2Runnable() {
                @Override
                public void run() {
                    frameWriter.writeHeaders(ctxServer(), 3, http2HeadersResponse, 0, false, newPromiseServer());
                    ctxServer().flush();
                }
            });
            awaitResponses();
            ArgumentCaptor<FullHttpMessage> responseCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
            verify(clientListener).messageReceived(responseCaptor.capture());
            capturedResponses = responseCaptor.getAllValues();
            assertEquals(response, capturedResponses.get(0));
            cleanupCapturedResponses();
            reset(clientListener);

            setServerLatch(1);
            httpHeaders = request2.headers();
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
            httpHeaders.remove(HttpHeaderNames.EXPECT);
            runInChannel(clientChannel, new Http2Runnable() {
                @Override
                public void run() {
                    frameWriter.writeData(ctxClient(), 3, payload.retain(), 0, true, newPromiseClient());
                    ctxClient().flush();
                }
            });
            awaitRequests();
            requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
            verify(serverListener).messageReceived(requestCaptor.capture());
            capturedRequests = requestCaptor.getAllValues();
            assertEquals(request2, capturedRequests.get(0));

            setClientLatch(1);
            httpHeaders = response2.headers();
            httpHeaders.setInt(HttpUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
            httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
            final Http2Headers http2HeadersResponse2 = new DefaultHttp2Headers().status(as("200"));
            runInChannel(serverConnectedChannel, new Http2Runnable() {
                @Override
                public void run() {
                    frameWriter.writeHeaders(ctxServer(), 3, http2HeadersResponse2, 0, true, newPromiseServer());
View Full Code Here

        return this;
    }

    public FullHttpRequest build() {
        FullHttpRequest req = new DefaultFullHttpRequest(httpVersion, method, uri);
        HttpHeaders headers = req.headers();

        if (host != null) {
            headers.set(HttpHeaderNames.HOST, host);
        }
        if (upgrade != null) {
            headers.set(HttpHeaderNames.UPGRADE, upgrade);
        }
        if (connection != null) {
            headers.set(HttpHeaderNames.CONNECTION, connection);
        }
        if (key != null) {
            headers.set(HttpHeaderNames.SEC_WEBSOCKET_KEY, key);
        }
        if (origin != null) {
            headers.set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, origin);
        }
        if (version != null) {
            headers.set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, version.toHttpHeaderValue());
        }
        return req;
    }
View Full Code Here

                wsPort = 80;
            }
        }

        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
        HttpHeaders headers = request.headers();

        headers.add(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET)
               .add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
               .add(HttpHeaderNames.SEC_WEBSOCKET_KEY, key)
               .add(HttpHeaderNames.HOST, wsURL.getHost() + ':' + wsPort);

        String originValue = "http://" + wsURL.getHost();
        if (wsPort != 80 && wsPort != 443) {
            // if the port is not standard (80/443) its needed to add the port to the header.
            // See http://tools.ietf.org/html/rfc6454#section-6.2
            originValue = originValue + ':' + wsPort;
        }
        headers.add(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, originValue);

        String expectedSubprotocol = expectedSubprotocol();
        if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
            headers.add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
        }

        headers.add(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "13");

        if (customHeaders != null) {
            headers.add(customHeaders);
        }
        return request;
    }
View Full Code Here

     * @throws WebSocketHandshakeException
     */
    @Override
    protected void verify(FullHttpResponse response) {
        final HttpResponseStatus status = HttpResponseStatus.SWITCHING_PROTOCOLS;
        final HttpHeaders headers = response.headers();

        if (!response.status().equals(status)) {
            throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
        }

        CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
        if (!HttpHeaderValues.WEBSOCKET.equalsIgnoreCase(upgrade)) {
            throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
        }

        CharSequence connection = headers.get(HttpHeaderNames.CONNECTION);
        if (!HttpHeaderValues.UPGRADE.equalsIgnoreCase(connection)) {
            throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
        }

        CharSequence accept = headers.get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT);
        if (accept == null || !accept.equals(expectedChallengeResponseString)) {
            throw new WebSocketHandshakeException(String.format(
                    "Invalid challenge. Actual: %s. Expected: %s", accept, expectedChallengeResponseString));
        }
    }
View Full Code Here

            path = "/";
        }

        // Format request
        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
        HttpHeaders headers = request.headers();
        headers.add(HttpHeaderNames.UPGRADE, WEBSOCKET)
               .add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
               .add(HttpHeaderNames.HOST, wsURL.getHost());

        int wsPort = wsURL.getPort();
        String originValue = "http://" + wsURL.getHost();
        if (wsPort != 80 && wsPort != 443) {
            // if the port is not standard (80/443) its needed to add the port to the header.
            // See http://tools.ietf.org/html/rfc6454#section-6.2
            originValue = originValue + ':' + wsPort;
        }

        headers.add(HttpHeaderNames.ORIGIN, originValue)
               .add(HttpHeaderNames.SEC_WEBSOCKET_KEY1, key1)
               .add(HttpHeaderNames.SEC_WEBSOCKET_KEY2, key2);

        String expectedSubprotocol = expectedSubprotocol();
        if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
            headers.add(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
        }

        if (customHeaders != null) {
            headers.add(customHeaders);
        }

        // Set Content-Length to workaround some known defect.
        // See also: http://www.ietf.org/mail-archive/web/hybi/current/msg02149.html
        headers.setInt(HttpHeaderNames.CONTENT_LENGTH, key3.length);
        request.content().writeBytes(key3);
        return request;
    }
View Full Code Here

        if (!response.status().equals(status)) {
            throw new WebSocketHandshakeException("Invalid handshake response getStatus: " + response.status());
        }

        HttpHeaders headers = response.headers();

        CharSequence upgrade = headers.get(HttpHeaderNames.UPGRADE);
        if (!WEBSOCKET.equalsIgnoreCase(upgrade)) {
            throw new WebSocketHandshakeException("Invalid handshake response upgrade: "
                    + upgrade);
        }

        CharSequence connection = headers.get(HttpHeaderNames.CONNECTION);
        if (!HttpHeaderValues.UPGRADE.equalsIgnoreCase(connection)) {
            throw new WebSocketHandshakeException("Invalid handshake response connection: "
                    + connection);
        }
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.