Package io.netty.handler.codec.http

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


    }

    @Override
    public void onWeightChanged(Http2Stream stream, short oldWeight) {
        FullHttpMessage msg = messageMap.get(stream.id());
        HttpHeaders headers = null;
        if (msg == null) {
            // msg may be null if a HTTP/2 frame event in received outside the HTTP message flow
            // For example a PRIORITY frame can be received in any state besides IDLE
            // and the HTTP message flow exists in OPEN.
            headers = new DefaultHttpHeaders();
            importOutOfMessageFlowHeaders(stream.id(), headers);
        } else {
            headers = getActiveHeaders(msg);
        }
        headers.set(HttpUtil.ExtensionHeaders.Names.STREAM_WEIGHT, stream.weight());
    }
View Full Code Here


    @Override
    public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight,
                    boolean exclusive) throws Http2Exception {
        FullHttpMessage msg = messageMap.get(streamId);
        if (msg == null) {
            HttpHeaders headers = outOfMessageFlowHeaders.remove(streamId);
            if (headers == null) {
                throw Http2Exception.protocolError("Priority Frame recieved for unknown stream id %d", streamId);
            }

            DefaultHttp2Headers.Builder builder = DefaultHttp2Headers.newBuilder();
View Full Code Here

        if (msg instanceof FullHttpMessage) {
            FullHttpMessage httpMsg = (FullHttpMessage) msg;
            boolean hasData = httpMsg.content().isReadable();

            // Convert and write the headers.
            HttpHeaders httpHeaders = httpMsg.headers();
            DefaultHttp2Headers.Builder http2Headers = DefaultHttp2Headers.newBuilder();
            if (msg instanceof HttpRequest) {
                addRequestHeaders((HttpRequest) msg, http2Headers);
            } else if (msg instanceof HttpResponse) {
                addResponseHeaders((HttpResponse) msg, http2Headers);
            }

            // Provide the user the opportunity to specify the streamId
            int streamId = 0;
            try {
                streamId = getStreamId(httpHeaders);
            } catch (Http2Exception e) {
                httpMsg.release();
                promise.setFailure(e);
                return;
            }

            // The Connection, Keep-Alive, Proxy-Connection, Transfer-Encoding,
            // and Upgrade headers are not valid and MUST not be sent.
            httpHeaders.remove(HttpHeaders.Names.CONNECTION);
            httpHeaders.remove(HttpHeaders.Names.KEEP_ALIVE);
            httpHeaders.remove(HttpHeaders.Names.PROXY_CONNECTION);
            httpHeaders.remove(HttpHeaders.Names.TRANSFER_ENCODING);

            // Add the HTTP headers which have not been consumed above
            for (Map.Entry<String, String> entry : httpHeaders.entries()) {
                http2Headers.add(entry.getKey(), entry.getValue());
            }

            if (hasData) {
                ChannelPromiseAggregator promiseAggregator = new ChannelPromiseAggregator(promise);
View Full Code Here

            chunk.content().retain();
            SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(currentStreamId, chunk.content());
            spdyDataFrame.setLast(chunk instanceof LastHttpContent);
            if (chunk instanceof LastHttpContent) {
                LastHttpContent trailer = (LastHttpContent) chunk;
                HttpHeaders trailers = trailer.trailingHeaders();
                if (trailers.isEmpty()) {
                    out.add(spdyDataFrame);
                } else {
                    // Create SPDY HEADERS frame out of trailers
                    SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(currentStreamId);
                    for (Map.Entry<String, String> entry: trailers) {
View Full Code Here

    }

    @SuppressWarnings("deprecation")
    private SpdySynStreamFrame createSynStreamFrame(HttpMessage httpMessage) throws Exception {
        // Get the Stream-ID, Associated-To-Stream-ID, Priority, URL, and scheme from the headers
        final HttpHeaders httpHeaders = httpMessage.headers();
        int streamID = httpHeaders.getInt(Names.STREAM_ID);
        int associatedToStreamId = httpHeaders.getInt(Names.ASSOCIATED_TO_STREAM_ID, 0);
        byte priority = (byte) httpHeaders.getInt(Names.PRIORITY, 0);
        String URL = httpHeaders.get(Names.URL);
        String scheme = httpHeaders.get(Names.SCHEME);
        httpHeaders.remove(Names.STREAM_ID);
        httpHeaders.remove(Names.ASSOCIATED_TO_STREAM_ID);
        httpHeaders.remove(Names.PRIORITY);
        httpHeaders.remove(Names.URL);
        httpHeaders.remove(Names.SCHEME);

        // The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
        // headers are not valid and MUST not be sent.
        httpHeaders.remove(HttpHeaders.Names.CONNECTION);
        httpHeaders.remove(HttpHeaders.Names.KEEP_ALIVE);
        httpHeaders.remove(HttpHeaders.Names.PROXY_CONNECTION);
        httpHeaders.remove(HttpHeaders.Names.TRANSFER_ENCODING);

        SpdySynStreamFrame spdySynStreamFrame =
                new DefaultSpdySynStreamFrame(streamID, associatedToStreamId, priority);

        // Unfold the first line of the message into name/value pairs
        SpdyHeaders frameHeaders = spdySynStreamFrame.headers();
        if (httpMessage instanceof FullHttpRequest) {
            HttpRequest httpRequest = (HttpRequest) httpMessage;
            frameHeaders.set(METHOD, httpRequest.method());
            frameHeaders.set(PATH, httpRequest.uri());
            frameHeaders.set(VERSION, httpMessage.protocolVersion());
        }
        if (httpMessage instanceof HttpResponse) {
            HttpResponse httpResponse = (HttpResponse) httpMessage;
            frameHeaders.set(STATUS, httpResponse.status());
            frameHeaders.set(PATH, URL);
            frameHeaders.set(VERSION, httpMessage.protocolVersion());
            spdySynStreamFrame.setUnidirectional(true);
        }

        // Replace the HTTP host header with the SPDY host header
        if (spdyVersion >= 3) {
            CharSequence host = httpHeaders.getUnconverted(HttpHeaders.Names.HOST);
            httpHeaders.remove(HttpHeaders.Names.HOST);
            frameHeaders.set(HOST, host);
        }

        // Set the SPDY scheme header
        if (scheme == null) {
View Full Code Here

    }

    @SuppressWarnings("deprecation")
    private SpdySynReplyFrame createSynReplyFrame(HttpResponse httpResponse) throws Exception {
        // Get the Stream-ID from the headers
        final HttpHeaders httpHeaders = httpResponse.headers();
        int streamID = httpHeaders.getInt(Names.STREAM_ID);
        httpHeaders.remove(Names.STREAM_ID);

        // The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
        // headers are not valid and MUST not be sent.
        httpHeaders.remove(HttpHeaders.Names.CONNECTION);
        httpHeaders.remove(HttpHeaders.Names.KEEP_ALIVE);
        httpHeaders.remove(HttpHeaders.Names.PROXY_CONNECTION);
        httpHeaders.remove(HttpHeaders.Names.TRANSFER_ENCODING);

        SpdySynReplyFrame spdySynReplyFrame = new DefaultSpdySynReplyFrame(streamID);
        SpdyHeaders frameHeaders = spdySynReplyFrame.headers();
        // Unfold the first line of the response into name/value pairs
        frameHeaders.set(STATUS, httpResponse.status());
View Full Code Here

                    key, expectedChallengeResponseString);
        }

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

        headers.add(Names.UPGRADE, WEBSOCKET)
               .add(Names.CONNECTION, Values.UPGRADE)
               .add(Names.SEC_WEBSOCKET_KEY, key)
               .add(Names.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(Names.SEC_WEBSOCKET_ORIGIN, originValue);

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

        headers.add(Names.SEC_WEBSOCKET_VERSION, "7");

        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());
        }

        String upgrade = headers.get(Names.UPGRADE);
        if (!AsciiString.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
            throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
        }

        String connection = headers.get(Names.CONNECTION);
        if (!AsciiString.equalsIgnoreCase(Values.UPGRADE, connection)) {
            throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
        }

        String accept = headers.get(Names.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

                    key, expectedChallengeResponseString);
        }

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

        headers.add(Names.UPGRADE, WEBSOCKET)
               .add(Names.CONNECTION, Values.UPGRADE)
               .add(Names.SEC_WEBSOCKET_KEY, key)
               .add(Names.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(Names.SEC_WEBSOCKET_ORIGIN, originValue);

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

        headers.add(Names.SEC_WEBSOCKET_VERSION, "8");

        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());
        }

        String upgrade = headers.get(Names.UPGRADE);
        if (!AsciiString.equalsIgnoreCase(Values.WEBSOCKET, upgrade)) {
            throw new WebSocketHandshakeException("Invalid handshake response upgrade: " + upgrade);
        }

        String connection = headers.get(Names.CONNECTION);
        if (!AsciiString.equalsIgnoreCase(Values.UPGRADE, connection)) {
            throw new WebSocketHandshakeException("Invalid handshake response connection: " + connection);
        }

        String accept = headers.get(Names.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

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.