|
1 | 1 | //! HTTP Upgrades
|
2 | 2 | //!
|
| 3 | +//! This module deals with managing [HTTP Upgrades][mdn] in hyper. Since |
| 4 | +//! several concepts in HTTP allow for first talking HTTP, and then converting |
| 5 | +//! to a different protocol, this module conflates them into a single API. |
| 6 | +//! Those include: |
| 7 | +//! |
| 8 | +//! - HTTP/1.1 Upgrades |
| 9 | +//! - HTTP `CONNECT` |
| 10 | +//! |
| 11 | +//! You are responsible for any other pre-requisites to establish an upgrade, |
| 12 | +//! such as sending the appropriate headers, methods, and status codes. You can |
| 13 | +//! then use [`on`][] to grab a `Future` which will resolve to the upgraded |
| 14 | +//! connection object, or an error if the upgrade fails. |
| 15 | +//! |
| 16 | +//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism |
| 17 | +//! |
| 18 | +//! # Client |
| 19 | +//! |
| 20 | +//! Sending an HTTP ugprade from the [`client`](super::client) involves setting |
| 21 | +//! either the appropriate method, if wanting to `CONNECT`, or headers such as |
| 22 | +//! `Upgrade` and `Connection`, on the `http::Request`. Once receiving the |
| 23 | +//! `http::Response` back, you must check for the specific information that the |
| 24 | +//! upgrade is agreed upon by the server (such as a `101` status code), and then |
| 25 | +//! get the `Future` from the `Response`. |
| 26 | +//! |
| 27 | +//! # Server |
| 28 | +//! |
| 29 | +//! Receiving upgrade requests in a server requires you to check the relevant |
| 30 | +//! headers in a `Request`, and if an upgrade should be done, you then send the |
| 31 | +//! corresponding headers in a response. To then wait for hyper to finish the |
| 32 | +//! upgrade, you call `on()` with the `Request`, and then can spawn a task |
| 33 | +//! awaiting it. |
| 34 | +//! |
| 35 | +//! # Example |
| 36 | +//! |
3 | 37 | //! See [this example][example] showing how upgrades work with both
|
4 | 38 | //! Clients and Servers.
|
5 | 39 | //!
|
@@ -60,6 +94,13 @@ pub struct Parts<T> {
|
60 | 94 | }
|
61 | 95 |
|
62 | 96 | /// Gets a pending HTTP upgrade from this message.
|
| 97 | +/// |
| 98 | +/// This can be called on the following types: |
| 99 | +/// |
| 100 | +/// - `http::Request<B>` |
| 101 | +/// - `http::Response<B>` |
| 102 | +/// - `&mut http::Request<B>` |
| 103 | +/// - `&mut http::Response<B>` |
63 | 104 | pub fn on<T: sealed::CanUpgrade>(msg: T) -> OnUpgrade {
|
64 | 105 | msg.on_upgrade()
|
65 | 106 | }
|
|
0 commit comments