Create a handshake request to open a connection. You must send the handshake request with :meth:`send_request`. You can modify it before sending it, for example to add HTTP headers. Returns: WebSocket handshake request event to send to the server.
(self)
| 94 | self.key = generate_key() |
| 95 | |
| 96 | def connect(self) -> Request: |
| 97 | """ |
| 98 | Create a handshake request to open a connection. |
| 99 | |
| 100 | You must send the handshake request with :meth:`send_request`. |
| 101 | |
| 102 | You can modify it before sending it, for example to add HTTP headers. |
| 103 | |
| 104 | Returns: |
| 105 | WebSocket handshake request event to send to the server. |
| 106 | |
| 107 | """ |
| 108 | headers = Headers() |
| 109 | headers["Host"] = build_host(self.uri.host, self.uri.port, self.uri.secure) |
| 110 | if self.uri.user_info: |
| 111 | headers["Authorization"] = build_authorization_basic(*self.uri.user_info) |
| 112 | if self.origin is not None: |
| 113 | headers["Origin"] = self.origin |
| 114 | headers["Upgrade"] = "websocket" |
| 115 | headers["Connection"] = "Upgrade" |
| 116 | headers["Sec-WebSocket-Key"] = self.key |
| 117 | headers["Sec-WebSocket-Version"] = "13" |
| 118 | if self.available_extensions is not None: |
| 119 | headers["Sec-WebSocket-Extensions"] = build_extension( |
| 120 | [ |
| 121 | (extension_factory.name, extension_factory.get_request_params()) |
| 122 | for extension_factory in self.available_extensions |
| 123 | ] |
| 124 | ) |
| 125 | if self.available_subprotocols is not None: |
| 126 | headers["Sec-WebSocket-Protocol"] = build_subprotocol( |
| 127 | self.available_subprotocols |
| 128 | ) |
| 129 | return Request(self.uri.resource_name, headers) |
| 130 | |
| 131 | def process_response(self, response: Response) -> None: |
| 132 | """ |