MCPcopy Index your code
hub / github.com/python-websockets/websockets / handshake

Method handshake

src/websockets/sync/client.py:76–102  ·  view source on GitHub ↗

Perform the opening handshake.

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

Source from the content-addressed store, hash-verified

74 )
75
76 def handshake(
77 self,
78 additional_headers: HeadersLike | None = None,
79 user_agent_header: str | None = USER_AGENT,
80 timeout: float | None = None,
81 ) -> None:
82 """
83 Perform the opening handshake.
84
85 """
86 with self.send_context(expected_state=CONNECTING):
87 self.request = self.protocol.connect()
88 if additional_headers is not None:
89 self.request.headers.update(additional_headers)
90 if user_agent_header is not None:
91 self.request.headers.setdefault("User-Agent", user_agent_header)
92 self.protocol.send_request(self.request)
93
94 if not self.response_rcvd.wait(timeout):
95 raise TimeoutError("timed out while waiting for handshake response")
96
97 # self.protocol.handshake_exc is set when the connection is lost before
98 # receiving a response, when the response cannot be parsed, or when the
99 # response fails the handshake.
100
101 if self.protocol.handshake_exc is not None:
102 raise self.protocol.handshake_exc
103
104 def process_event(self, event: Event) -> None:
105 """

Callers 1

connectFunction · 0.45

Calls 4

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

Tested by

no test coverage detected