|
| 1 | +--- |
| 2 | +title: Upgrade from 0.14 to 1 |
| 3 | +layout: guide |
| 4 | +permalink: /guides/1/upgrading/ |
| 5 | +--- |
| 6 | + |
| 7 | +This guide is meant to help you upgrade from v0.14 of hyper to v1. |
| 8 | + |
| 9 | +## Backports and Deprecations |
| 10 | + |
| 11 | +Before upgrading, you can start preparing your 0.14 code base by enabling the |
| 12 | +`backports` and `deprecated` features of hyper in your `Cargo.toml`. Like |
| 13 | +this: |
| 14 | + |
| 15 | +```toml |
| 16 | +[dependencies] |
| 17 | +hyper = { version = "0.14", features = ["etc", "backports", "deprecated"] } |
| 18 | +``` |
| 19 | + |
| 20 | +The `backports` feature brings several of the new types from 1.0 to 0.14. If |
| 21 | +you enable `deprecated` feature as well, it will add deprecation warnings to |
| 22 | +any of hyper's types that have direct backports available. |
| 23 | + |
| 24 | +**NOTE**: This won't give you warnings about changes where backports were not |
| 25 | +able to be provided. |
| 26 | + |
| 27 | +## Changelog |
| 28 | + |
| 29 | +As a general rule, we tried hard to mark every possible breaking change in the |
| 30 | +[changelog][]. Read through the "breaking changes" section of the 1.0 releases |
| 31 | +(including the RC 1-4), which will provide suggestions on how to overcome each |
| 32 | +one. |
| 33 | + |
| 34 | +## `hyper::Body` |
| 35 | + |
| 36 | +The `Body` type has changed to be a trait (what used to be `HttpBody`). |
| 37 | + |
| 38 | +The 0.14 `Body` could be multiple variants, and in v1 they have been split into |
| 39 | +[distinct types][http-body-util]. You'll benefit from analzying each place you |
| 40 | +use `hyper::Body` to decide which solution to switch to. |
| 41 | + |
| 42 | +- In general, if you don't need a specific variant, consider making your usage |
| 43 | + generic, accepting an `impl Body` (or `where B: Body`). |
| 44 | +- If you want a type that can be any variant, you could use `BoxBody`. |
| 45 | +- Otherwise, the [more specific variants][http-body-util] allow for a more |
| 46 | + explicit API in your code. |
| 47 | + |
| 48 | +## `hyper::Client` |
| 49 | + |
| 50 | +The higher-level pooling `Client` was removed from hyper 1.0. A similar type |
| 51 | +was added to [`hyper-util`][], called [`client::legacy::Client`][legacy]. It's |
| 52 | +mostly a drop-in replacement. |
| 53 | + |
| 54 | +## `hyper::Server` |
| 55 | + |
| 56 | +The v0.14 `hyper::Server` does not have a drop-in replacement, since it had |
| 57 | +problems. |
| 58 | + |
| 59 | +For a server type that can handle both HTTP/1 and HTTP/2 at the same time, |
| 60 | +use the [`server::conn::auto::Builder`][auto] from [`hyper-util`][]. |
| 61 | + |
| 62 | +The listening server acceptor can be replaced with a simple loop. |
| 63 | + |
| 64 | + |
| 65 | +[changelog]: https://github.com/hyperium/hyper/blob/master/CHANGELOG.md#v100-2023-11-15 |
| 66 | +[`hyper-util`]: https://crates.io/crates/hyper-util |
| 67 | +[legacy]: https://docs.rs/hyper-util/latest/hyper_util/client/legacy/struct.Client.html |
| 68 | +[auto]: https://docs.rs/hyper-util/latest/hyper_util/server/conn/auto/struct.Builder.html |
0 commit comments