feat(http1): Add higher-level HTTP upgrade support to Client and Server (#1563)
- Adds `Body::on_upgrade()` that returns an `OnUpgrade` future.
- Adds `hyper::upgrade` module containing types for dealing with
  upgrades.
- Adds `server::conn::Connection::with_upgrades()` method to enable
  these upgrades when using lower-level API (because of a missing
  `Send` bound on the transport generic).
- Client connections are automatically enabled.
- Optimizes request parsing, to make up for extra work to look for
  upgrade requests.
  - Returns a smaller `DecodedLength` type instead of the fatter
    `Decoder`, which should also allow a couple fewer branches.
  - Removes the `Decode::Ignore` wrapper enum, and instead ignoring
    1xx responses is handled directly in the response parsing code.
Ref #1563 
Closes #1395
			
			
This commit is contained in:
		| @@ -8,6 +8,7 @@ use tokio_io::{AsyncRead, AsyncWrite}; | ||||
| use body::Payload; | ||||
| use ::common::{Exec, Never}; | ||||
| use headers; | ||||
| use ::proto::Dispatched; | ||||
| use super::{PipeToSendStream, SendBuf}; | ||||
| use ::{Body, Request, Response}; | ||||
|  | ||||
| @@ -16,7 +17,7 @@ type ClientRx<B> = ::client::dispatch::Receiver<Request<B>, Response<Body>>; | ||||
| /// other handles to it have been dropped, so that it can shutdown. | ||||
| type ConnDropRef = mpsc::Sender<Never>; | ||||
|  | ||||
| pub struct Client<T, B> | ||||
| pub(crate) struct Client<T, B> | ||||
| where | ||||
|     B: Payload, | ||||
| { | ||||
| @@ -54,7 +55,7 @@ where | ||||
|     T: AsyncRead + AsyncWrite + Send + 'static, | ||||
|     B: Payload + 'static, | ||||
| { | ||||
|     type Item = (); | ||||
|     type Item = Dispatched; | ||||
|     type Error = ::Error; | ||||
|  | ||||
|     fn poll(&mut self) -> Poll<Self::Item, Self::Error> { | ||||
| @@ -153,7 +154,7 @@ where | ||||
|                         Ok(Async::Ready(None)) | | ||||
|                         Err(_) => { | ||||
|                             trace!("client::dispatch::Sender dropped"); | ||||
|                             return Ok(Async::Ready(())); | ||||
|                             return Ok(Async::Ready(Dispatched::Shutdown)); | ||||
|                         } | ||||
|                     } | ||||
|                 }, | ||||
|   | ||||
| @@ -7,6 +7,7 @@ use ::body::Payload; | ||||
| use ::common::Exec; | ||||
| use ::headers; | ||||
| use ::service::Service; | ||||
| use ::proto::Dispatched; | ||||
| use super::{PipeToSendStream, SendBuf}; | ||||
|  | ||||
| use ::{Body, Response}; | ||||
| @@ -82,7 +83,7 @@ where | ||||
|     S::Future: Send + 'static, | ||||
|     B: Payload, | ||||
| { | ||||
|     type Item = (); | ||||
|     type Item = Dispatched; | ||||
|     type Error = ::Error; | ||||
|  | ||||
|     fn poll(&mut self) -> Poll<Self::Item, Self::Error> { | ||||
| @@ -95,12 +96,13 @@ where | ||||
|                     }) | ||||
|                 }, | ||||
|                 State::Serving(ref mut srv) => { | ||||
|                     return srv.poll_server(&mut self.service, &self.exec); | ||||
|                     try_ready!(srv.poll_server(&mut self.service, &self.exec)); | ||||
|                     return Ok(Async::Ready(Dispatched::Shutdown)); | ||||
|                 } | ||||
|                 State::Closed => { | ||||
|                     // graceful_shutdown was called before handshaking finished, | ||||
|                     // nothing to do here... | ||||
|                     return Ok(Async::Ready(())); | ||||
|                     return Ok(Async::Ready(Dispatched::Shutdown)); | ||||
|                 } | ||||
|             }; | ||||
|             self.state = next; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user