Home / Function/ FullHttpResponse() — netty Function Reference

FullHttpResponse() — netty Function Reference

Architecture documentation for the FullHttpResponse() function in WebSocketServerHandshaker08.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  98ba87f0_d4d2_d44e_132d_56f05ae00c70["FullHttpResponse()"]
  f744aa36_e83b_c1d5_128a_5b925f5be96a["WebSocketServerHandshaker08"]
  98ba87f0_d4d2_d44e_132d_56f05ae00c70 -->|defined in| f744aa36_e83b_c1d5_128a_5b925f5be96a
  style 98ba87f0_d4d2_d44e_132d_56f05ae00c70 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08.java lines 138–181

    @Override
    protected FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders headers) {
        HttpMethod method = req.method();
        if (!GET.equals(method)) {
            throw new WebSocketServerHandshakeException("Invalid WebSocket handshake method: " + method, req);
        }

        CharSequence key = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_KEY);
        if (key == null) {
            throw new WebSocketServerHandshakeException("not a WebSocket request: missing key", req);
        }

        FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.SWITCHING_PROTOCOLS,
                req.content().alloc().buffer(0));

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

        String acceptSeed = key + WEBSOCKET_08_ACCEPT_GUID;
        byte[] sha1 = WebSocketUtil.sha1(acceptSeed.getBytes(CharsetUtil.US_ASCII));
        String accept = WebSocketUtil.base64(sha1);

        if (logger.isDebugEnabled()) {
            logger.debug("WebSocket version 08 server handshake key: {}, response: {}", key, accept);
        }

        res.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET)
                     .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
                     .set(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, accept);

        String subprotocols = req.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL);
        if (subprotocols != null) {
            String selectedSubprotocol = selectSubprotocol(subprotocols);
            if (selectedSubprotocol == null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Requested subprotocol(s) not supported: {}", subprotocols);
                }
            } else {
                res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
            }
        }
        return res;
    }

Subdomains

Frequently Asked Questions

What does FullHttpResponse() do?
FullHttpResponse() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08.java.
Where is FullHttpResponse() defined?
FullHttpResponse() is defined in codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08.java at line 138.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free