|
1 | | -//! Facilities for HTTP/1 upgrades. |
| 1 | +//! Facilities for HTTP/1.1 upgrades. |
| 2 | +//! |
| 3 | +//! HTTP/1.1 specifies an `Upgrade` header field that may be used in tandem with the `Connection` |
| 4 | +//! header field as a simple mechanism to transition from HTTP/1.1 to another protocol. This crate |
| 5 | +//! provides [`tower`] middleware that enable upgrades to HTTP/2 for services running within a |
| 6 | +//! [`tokio`] runtime. |
| 7 | +//! |
| 8 | +//! Use [`Service::new()`] to add upgrade support to a [`tower::Service`]. |
| 9 | +//! |
| 10 | +//! [RFC 9110 § 7.6.1][rfc9110-connection] for more information about the `Connection` header |
| 11 | +//! field, [RFC 9110 § 7.8][rfc9110-upgrade] for more information about HTTP/1.1's `Upgrade` |
| 12 | +//! header field, and [RFC 9110 § 15.2.2][rfc9110-101] for more information about the |
| 13 | +//! `101 (Switching Protocols)` response status code. |
| 14 | +//! |
| 15 | +//! Note that HTTP/2 does *NOT* provide support for the `Upgrade` header field, per |
| 16 | +//! [RFC 9113 § 8.6][rfc9113]. HTTP/2 is a multiplexed protocol, and connection upgrades are |
| 17 | +//! thus inapplicable. |
| 18 | +//! |
| 19 | +//! [rfc9110-connection]: https://www.rfc-editor.org/rfc/rfc9110#name-connection |
| 20 | +//! [rfc9110-upgrade]: https://www.rfc-editor.org/rfc/rfc9110#field.upgrade |
| 21 | +//! [rfc9110-101]: https://www.rfc-editor.org/rfc/rfc9110#name-101-switching-protocols |
| 22 | +//! [rfc9113]: https://www.rfc-editor.org/rfc/rfc9113.html#name-the-upgrade-header-field |
2 | 23 |
|
3 | 24 | pub use self::upgrade::Service; |
4 | 25 |
|
5 | 26 | pub mod glue; |
6 | 27 | pub mod upgrade; |
7 | 28 |
|
| 29 | +/// Removes connection headers from the given [`HeaderMap`][http::HeaderMap]. |
| 30 | +/// |
| 31 | +/// An HTTP proxy is required to do this, according to [RFC 9110 § 7.6.1 ¶ 5][rfc9110-761-5]: |
| 32 | +/// |
| 33 | +/// > Intermediaries MUST parse a received Connection header field before a message is forwarded |
| 34 | +/// > and, for each connection-option in this field, remove any header or trailer field(s) from the |
| 35 | +/// > message with the same name as the connection-option, and then remove the Connection header |
| 36 | +/// > field itself (or replace it with the intermediary's own control options for the forwarded |
| 37 | +/// > message). |
| 38 | +/// |
| 39 | +/// This function additionally removes some headers mentioned in |
| 40 | +/// [RFC 9110 § 7.6.1 ¶ 7-8.5][rfc9110-761-7] |
| 41 | +/// |
| 42 | +/// > Furthermore, intermediaries SHOULD remove or replace fields that are known to require removal |
| 43 | +/// > before forwarding, whether or not they appear as a connection-option, after applying those |
| 44 | +/// > fields' semantics. This includes but is not limited to: |
| 45 | +/// > |
| 46 | +/// > - `Proxy-Connection` (Appendix C.2.2 of [HTTP/1.1]) |
| 47 | +/// > - `Keep-Alive` (Section 19.7.1 of [RFC2068]) |
| 48 | +/// > - `TE` (Section 10.1.4) |
| 49 | +/// > - `Transfer-Encoding` (Section 6.1 of [HTTP/1.1]) |
| 50 | +/// > - `Upgrade` (Section 7.8) |
| 51 | +/// |
| 52 | +/// [rfc9110-761-5]: https://www.rfc-editor.org/rfc/rfc9110#section-7.6.1-5 |
| 53 | +/// [rfc9110-761-7]: https://www.rfc-editor.org/rfc/rfc9110#section-7.6.1-7 |
8 | 54 | pub fn strip_connection_headers(headers: &mut http::HeaderMap) { |
9 | 55 | use http::header; |
10 | 56 | if let Some(val) = headers.remove(header::CONNECTION) { |
|
0 commit comments