private static boolean isSameOrigin(ServiceRequestContext ctx, RequestHeaders headers, String origin) {
        final int schemeDelimiter = origin.indexOf("://");
        if (schemeDelimiter < 0) {
            return false;
        }

        final String scheme = origin.substring(0, schemeDelimiter);
        final SessionProtocol originSessionProtocol = SessionProtocol.find(scheme);
        if (originSessionProtocol == null) {
            return false;
        }

        if ((ctx.sessionProtocol().isHttp() && originSessionProtocol.isHttp()) ||
            (ctx.sessionProtocol().isHttps() && originSessionProtocol.isHttps())) {
            // The same scheme.
        } else {
            return false;
        }

        final String authority = headers.authority();
        assert authority != null;
        final HostAndPort authorityHostAndPort = HostAndPort.fromString(authority);
        final String authorityHost = authorityHostAndPort.getHost();
        final int authorityPort = authorityHostAndPort.getPortOrDefault(
                ctx.sessionProtocol().defaultPort());

        final HostAndPort originHostAndPort = HostAndPort.fromString(origin.substring(schemeDelimiter + 3));
        final String originHost = originHostAndPort.getHost();
        final int originPort = originHostAndPort.getPortOrDefault(originSessionProtocol.defaultPort());

        return authorityPort == originPort && authorityHost.equals(originHost);
    }
Handles the HTTP/2 web socket handshake described in
<a href="https://datatracker.ietf.org/doc/html/rfc8441">Bootstrapping WebSockets with HTTP/2</a>.
These are examples of a request and the corresponding response:

<p>Request:
<pre>
HEADERS + END_HEADERS
:method = CONNECT
:protocol = websocket
:scheme = https
:path = /chat
:authority = server.example.com
sec-websocket-protocol = chat, superchat
sec-websocket-extensions = permessage-deflate
sec-websocket-version = 13
origin = http://www.example.com
</pre>

<p>Response:
<pre>
HEADERS + END_HEADERS
:status = 200
sec-websocket-protocol = chat
</pre>
core/src/main/java/com/linecorp/armeria/internal/server/websocket/DefaultWebSocketService.java