Skip to content

Commit

Permalink
fix(server): avoid unwrapping for the Future impl of HTTP/1 `Upgrad…
Browse files Browse the repository at this point in the history
…eableConnection` (#3627)

Closes #3621
  • Loading branch information
DDtKey authored Apr 10, 2024
1 parent 203d1b0 commit b79be91
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/server/conn/http1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,19 @@ where
type Output = crate::Result<()>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match ready!(Pin::new(&mut self.inner.as_mut().unwrap().conn).poll(cx)) {
Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())),
Ok(proto::Dispatched::Upgrade(pending)) => {
let (io, buf, _) = self.inner.take().unwrap().conn.into_inner();
pending.fulfill(Upgraded::new(io, buf));
Poll::Ready(Ok(()))
if let Some(conn) = self.inner.as_mut() {
match ready!(Pin::new(&mut conn.conn).poll(cx)) {
Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())),
Ok(proto::Dispatched::Upgrade(pending)) => {
let (io, buf, _) = self.inner.take().unwrap().conn.into_inner();
pending.fulfill(Upgraded::new(io, buf));
Poll::Ready(Ok(()))
}
Err(e) => Poll::Ready(Err(e)),
}
Err(e) => Poll::Ready(Err(e)),
} else {
// inner is `None`, meaning the connection was upgraded, thus it's `Poll::Ready(Ok(()))`
Poll::Ready(Ok(()))
}
}
}

0 comments on commit b79be91

Please sign in to comment.