Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept multiple protocols in upgrade request. #1210

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions client/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ pub struct UpgradeResponse {
impl<'a> UpgradeRequest<'a> {
pub fn protocol<V>(mut self, proto: V) -> UpgradeRequestWithProtocol<'a>
where
V: TryInto<HeaderValue>,
V::Error: std::error::Error + Send + Sync + 'static,
V: IntoIterator,
V::Item: TryInto<HeaderValue>,
<V::Item as TryInto<HeaderValue>>::Error: Into<crate::http::Error>,
{
match proto.try_into() {
Ok(v) => {
self.req.headers_mut().insert(header::UPGRADE, v);
}
Err(e) => {
self.push_error(Error::Std(Box::new(e)));
let res = proto
.into_iter()
.map(|proto| proto.try_into().map_err(|e| Error::Std(Box::new(e.into()))))
.collect::<Result<Vec<_>, Error>>();

match res {
Ok(proto) => {
for proto in proto {
self.req.headers_mut().append(header::UPGRADE, proto);
}
}
Err(e) => self.push_error(e),
};

self.mutate_marker()
Expand Down
Loading