Skip to content

Commit

Permalink
feat(server): add Request.ssl() to get underlying ssl stream
Browse files Browse the repository at this point in the history
Closes #627
  • Loading branch information
seanmonstar committed Aug 12, 2015
1 parent 1a91835 commit 7909829
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/server/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@ impl<'a, 'b: 'a> Request<'a, 'b> {
})
}

/// Get a reference to the underlying `NetworkStream`.
#[inline]
pub fn downcast_ref<T: NetworkStream>(&self) -> Option<&T> {
self.body.get_ref().get_ref().downcast_ref()
}

/// Get a reference to the underlying Ssl stream, if connected
/// over HTTPS.
///
/// # Example
///
/// ```rust
/// # extern crate hyper;
/// # #[cfg(feature = "openssl")]
/// extern crate openssl;
/// # #[cfg(feature = "openssl")]
/// use openssl::ssl::SslStream;
/// # fn main() {}
/// # #[cfg(feature = "openssl")]
/// # fn doc_ssl(req: hyper::server::Request) {
/// let maybe_ssl = req.ssl::<SslStream>();
/// # }
/// ```
#[inline]
pub fn ssl<T: NetworkStream>(&self) -> Option<&T> {
use ::net::HttpsStream;
match self.downcast_ref() {
Some(&HttpsStream::Https(ref s)) => Some(s),
_ => None
}
}

/// Deconstruct a Request into its constituent parts.
#[inline]
pub fn deconstruct(self) -> (SocketAddr, Method, Headers,
Expand Down

0 comments on commit 7909829

Please sign in to comment.