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

feat(server): add try_into_parts() to conn::Connection #1531

Merged
merged 1 commit into from Jun 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/server/conn.rs
Expand Up @@ -342,20 +342,28 @@ where
/// This should only be called after `poll_without_shutdown` signals
/// that the connection is "done". Otherwise, it may not have finished
/// flushing all necessary HTTP bytes.
///
/// # Panics
/// This method will panic if this connection is using an h2 protocol.
pub fn into_parts(self) -> Parts<I, S> {
let (io, read_buf, dispatch) = match self.conn.unwrap() {
self.try_into_parts().unwrap_or_else(|| panic!("h2 cannot into_inner"))
}

/// Return the inner IO object, and additional information, if available.
///
/// This method will return a `None` if this connection is using an h2 protocol.
pub fn try_into_parts(self) -> Option<Parts<I, S>> {
match self.conn.unwrap() {
Either::A(h1) => {
h1.into_inner()
let (io, read_buf, dispatch) = h1.into_inner();
Some(Parts {
io: io,
read_buf: read_buf,
service: dispatch.into_service(),
_inner: (),
})
},
Either::B(_h2) => {
panic!("h2 cannot into_inner");
}
};
Parts {
io: io,
read_buf: read_buf,
service: dispatch.into_service(),
_inner: (),
Either::B(_h2) => None,
}
}

Expand Down