MCPcopy Create free account
hub / github.com/python-websockets/websockets / handshake

Method handshake

src/websockets/asyncio/client.py:88–115  ·  view source on GitHub ↗

Perform the opening handshake.

(
        self,
        additional_headers: HeadersLike | None = None,
        user_agent_header: str | None = USER_AGENT,
    )

Source from the content-addressed store, hash-verified

86 self.response_rcvd: asyncio.Future[None] = self.loop.create_future()
87
88 async def handshake(
89 self,
90 additional_headers: HeadersLike | None = None,
91 user_agent_header: str | None = USER_AGENT,
92 ) -> None:
93 """
94 Perform the opening handshake.
95
96 """
97 async with self.send_context(expected_state=CONNECTING):
98 self.request = self.protocol.connect()
99 if additional_headers is not None:
100 self.request.headers.update(additional_headers)
101 if user_agent_header is not None:
102 self.request.headers.setdefault("User-Agent", user_agent_header)
103 self.protocol.send_request(self.request)
104
105 await asyncio.wait(
106 [self.response_rcvd, self.connection_lost_waiter],
107 return_when=asyncio.FIRST_COMPLETED,
108 )
109
110 # self.protocol.handshake_exc is set when the connection is lost before
111 # receiving a response, when the response cannot be parsed, or when the
112 # response fails the handshake.
113
114 if self.protocol.handshake_exc is not None:
115 raise self.protocol.handshake_exc
116
117 def process_event(self, event: Event) -> None:
118 """

Callers 1

__await_impl__Method · 0.45

Calls 4

connectMethod · 0.80
send_requestMethod · 0.80
send_contextMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected