def _initiate_connection(self, request: Request) -> bytes:
    self._initiating_request = request
    self._nonce = generate_nonce()
    headers = [(b'Host', request.host.encode('ascii')), (b'Upgrade', b'WebSocket'), (b'Connection', b'Upgrade'), (b'Sec-WebSocket-Key', self._nonce), (b'Sec-WebSocket-Version', WEBSOCKET_VERSION)]
    if request.subprotocols:
        headers.append((b'Sec-WebSocket-Protocol', ', '.join(request.subprotocols).encode('ascii')))
    if request.extensions:
        offers = {e.name: e.offer() for e in request.extensions}
        extensions = []
        for (name, params) in offers.items():
            name = name.encode('ascii')
            if (params is True):
                extensions.append(name)
            elif params:
                extensions.append((b'%s; %s' % (name, params.encode('ascii'))))
        if extensions:
            headers.append((b'Sec-WebSocket-Extensions', b', '.join(extensions)))
    upgrade = h11.Request(method=b'GET', target=request.target.encode('ascii'), headers=(headers + request.extra_headers))
    return self._h11_connection.send(upgrade)
def _initiate_connection(self, request: Request) -> bytes:
    self._initiating_request = request
    self._nonce = generate_nonce()
    headers = [(b'Host', request.host.encode('ascii')), (b'Upgrade', b'WebSocket'), (b'Connection', b'Upgrade'), (b'Sec-WebSocket-Key', self._nonce), (b'Sec-WebSocket-Version', WEBSOCKET_VERSION)]
    if request.subprotocols:
        headers.append((b'Sec-WebSocket-Protocol', ', '.join(request.subprotocols).encode('ascii')))
    if request.extensions:
        offers = {e.name: e.offer() for e in request.extensions}
        extensions = []
        for (name, params) in offers.items():
            name = name.encode('ascii')
            if (params is True):
                extensions.append(name)
            elif params:
                extensions.append((b'%s; %s' % (name, params.encode('ascii'))))
        if extensions:
            headers.append((b'Sec-WebSocket-Extensions', b', '.join(extensions)))
    upgrade = h11.Request(method=b'GET', target=request.target.encode('ascii'), headers=(headers + request.extra_headers))
    return self._h11_connection.send(upgrade)