Select a subprotocol from the ones provided, and prepare a response for the client.
(
self,
protocols: impl IntoIterator<Item = (S, P)>,
)
| 145 | |
| 146 | /// Select a subprotocol from the ones provided, and prepare a response for the client. |
| 147 | pub fn select_protocol<S, P>( |
| 148 | self, |
| 149 | protocols: impl IntoIterator<Item = (S, P)>, |
| 150 | ) -> (WebSocketResponse, PendingWebSocket, Option<P>) |
| 151 | where |
| 152 | S: for<'a> PartialEq<&'a str> + TryInto<HeaderValue>, |
| 153 | { |
| 154 | let (proto_header, proto) = self |
| 155 | .requested_protocol |
| 156 | .as_ref() |
| 157 | .and_then(|proto| proto.select(protocols)) |
| 158 | .unzip(); |
| 159 | let (resp, ws) = self.into_response(proto_header); |
| 160 | (resp, ws, proto) |
| 161 | } |
| 162 | |
| 163 | /// Prepare a response with no subprotocol selected. |
| 164 | #[inline] |
no test coverage detected