diff --git a/src/client/connect.rs b/src/client/connect.rs
index fdcc84a530..d347426e3c 100644
--- a/src/client/connect.rs
+++ b/src/client/connect.rs
@@ -6,9 +6,11 @@
//! establishes connections over TCP.
//! - The [`Connect`](Connect) trait and related types to build custom connectors.
use std::error::Error as StdError;
+use std::mem;
+use bytes::{BufMut, BytesMut};
use futures::Future;
-use http::Uri;
+use http::{uri, Uri};
use tokio_io::{AsyncRead, AsyncWrite};
#[cfg(feature = "runtime")] pub use self::http::HttpConnector;
@@ -79,6 +81,144 @@ impl Destination {
self.uri.port()
}
+ /// Update the scheme of this destination.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use hyper::client::connect::Destination;
+ /// # fn with_dst(mut dst: Destination) {
+ /// // let mut dst = some_destination...
+ /// // Change from "http://"...
+ /// assert_eq!(dst.scheme(), "http");
+ ///
+ /// // to "ws://"...
+ /// dst.set_scheme("ws");
+ /// assert_eq!(dst.scheme(), "ws");
+ /// # }
+ /// ```
+ ///
+ /// # Error
+ ///
+ /// Returns an error if the string is not a valid scheme.
+ pub fn set_scheme(&mut self, scheme: &str) -> ::Result<()> {
+ let scheme = scheme.parse().map_err(::error::Parse::from)?;
+ self.update_uri(move |parts| {
+ parts.scheme = Some(scheme);
+ })
+ }
+
+ /// Update the host of this destination.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use hyper::client::connect::Destination;
+ /// # fn with_dst(mut dst: Destination) {
+ /// // let mut dst = some_destination...
+ /// // Change from "hyper.rs"...
+ /// assert_eq!(dst.host(), "hyper.rs");
+ ///
+ /// // to "some.proxy"...
+ /// dst.set_host("some.proxy");
+ /// assert_eq!(dst.host(), "some.proxy");
+ /// # }
+ /// ```
+ ///
+ /// # Error
+ ///
+ /// Returns an error if the string is not a valid hostname.
+ pub fn set_host(&mut self, host: &str) -> ::Result<()> {
+ if host.contains(&['@',':'][..]) {
+ return Err(::error::Parse::Uri.into());
+ }
+ let auth = if let Some(port) = self.port() {
+ format!("{}:{}", host, port).parse().map_err(::error::Parse::from)?
+ } else {
+ host.parse().map_err(::error::Parse::from)?
+ };
+ self.update_uri(move |parts| {
+ parts.authority = Some(auth);
+ })
+ }
+
+ /// Update the port of this destination.
+ ///
+ /// # Example
+ ///
+ /// ```rust
+ /// # use hyper::client::connect::Destination;
+ /// # fn with_dst(mut dst: Destination) {
+ /// // let mut dst = some_destination...
+ /// // Change from "None"...
+ /// assert_eq!(dst.port(), None);
+ ///
+ /// // to "4321"...
+ /// dst.set_port(4321);
+ /// assert_eq!(dst.port(), Some(4321));
+ ///
+ /// // Or remove the port...
+ /// dst.set_port(None);
+ /// assert_eq!(dst.port(), None);
+ /// # }
+ /// ```
+ pub fn set_port
(&mut self, port: P)
+ where
+ P: Into