Skip to content

Commit b79be91

Browse files
authoredApr 10, 2024··
fix(server): avoid unwrapping for the Future impl of HTTP/1 UpgradeableConnection (#3627)
Closes #3621
1 parent 203d1b0 commit b79be91

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed
 

‎src/server/conn/http1.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,19 @@ where
501501
type Output = crate::Result<()>;
502502

503503
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
504-
match ready!(Pin::new(&mut self.inner.as_mut().unwrap().conn).poll(cx)) {
505-
Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())),
506-
Ok(proto::Dispatched::Upgrade(pending)) => {
507-
let (io, buf, _) = self.inner.take().unwrap().conn.into_inner();
508-
pending.fulfill(Upgraded::new(io, buf));
509-
Poll::Ready(Ok(()))
504+
if let Some(conn) = self.inner.as_mut() {
505+
match ready!(Pin::new(&mut conn.conn).poll(cx)) {
506+
Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())),
507+
Ok(proto::Dispatched::Upgrade(pending)) => {
508+
let (io, buf, _) = self.inner.take().unwrap().conn.into_inner();
509+
pending.fulfill(Upgraded::new(io, buf));
510+
Poll::Ready(Ok(()))
511+
}
512+
Err(e) => Poll::Ready(Err(e)),
510513
}
511-
Err(e) => Poll::Ready(Err(e)),
514+
} else {
515+
// inner is `None`, meaning the connection was upgraded, thus it's `Poll::Ready(Ok(()))`
516+
Poll::Ready(Ok(()))
512517
}
513518
}
514519
}

0 commit comments

Comments
 (0)
Please sign in to comment.