Skip to main content

hyper/
lib.rs

1#![deny(missing_docs)]
2#![deny(missing_debug_implementations)]
3#![cfg_attr(test, deny(rust_2018_idioms))]
4#![cfg_attr(
5    any(all(test, feature = "full"), feature = "__deny_warnings"),
6    deny(warnings, unreachable_pub)
7)]
8#![cfg_attr(all(test, feature = "nightly"), feature(test))]
9#![cfg_attr(docsrs, feature(doc_cfg))]
10
11//! # hyper
12//!
13//! hyper is a **fast** and **correct** HTTP implementation written in and for Rust.
14//!
15//! ## Features
16//!
17//! - HTTP/1 and HTTP/2
18//! - Asynchronous design
19//! - Leading in performance
20//! - Tested and **correct**
21//! - Extensive production use
22//! - [Client](client/index.html) and [Server](server/index.html) APIs
23//!
24//! If just starting out, **check out the [Guides](https://hyper.rs/guides/1/)
25//! first.**
26//!
27//! ## "Low-level"
28//!
29//! hyper is a lower-level HTTP library, meant to be a building block
30//! for libraries and applications.
31//!
32//! If looking for just a convenient HTTP client, consider the
33//! [reqwest](https://crates.io/crates/reqwest) crate.
34//!
35//! # Cancel safety
36//!
37//! Futures returned by hyper are cancel safe: dropping a future before it
38//! completes is the supported way to cancel the operation. The protocol in
39//! use changes what that cancellation actually does on the wire:
40//!
41//! - **HTTP/1** has no in-protocol way to abort a single request without
42//!   affecting the shared connection, so dropping an in-flight request future
43//!   closes the underlying TCP connection. Any subsequent call on the same
44//!   `SendRequest` returns a `canceled` error; the connection cannot be
45//!   reused.
46//! - **HTTP/2** resets the single stream with `RST_STREAM` (`CANCEL` error
47//!   code) and notifies the peer immediately rather than continuing to
48//!   deliver a response body that would be discarded. The shared connection
49//!   stays usable for other in-flight and future requests.
50//!
51//! See the documentation on individual futures — for example
52//! `SendRequest::send_request` in `client::conn::http1` and the equivalent
53//! in `client::conn::http2` — for the protocol-specific behavior on
54//! cancellation.
55//!
56//! # Optional Features
57//!
58//! hyper uses a set of [feature flags] to reduce the amount of compiled code.
59//! It is possible to just enable certain features over others. By default,
60//! hyper does not enable any features but allows one to enable a subset for
61//! their use case. Below is a list of the available feature flags. You may
62//! also notice above each function, struct and trait there is listed one or
63//! more feature flags that are required for that item to be used.
64//!
65//! If you are new to hyper it is possible to enable the `full` feature flag
66//! which will enable all public APIs. Beware though that this will pull in
67//! many extra dependencies that you may not need.
68//!
69//! The following optional features are available:
70//!
71//! - `http1`: Enables HTTP/1 support.
72//! - `http2`: Enables HTTP/2 support.
73//! - `client`: Enables the HTTP `client`.
74//! - `server`: Enables the HTTP `server`.
75//!
76//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
77//!
78//! ## Unstable Features
79//!
80//! hyper includes a set of unstable optional features that can be enabled through the use of a
81//! feature flag and a [configuration flag].
82//!
83//! The following is a list of feature flags and their corresponding `RUSTFLAG`:
84//!
85//! - `ffi`: Enables C API for hyper `hyper_unstable_ffi`.
86//! - `tracing`: Enables debug logging with `hyper_unstable_tracing`.
87//!
88//! For example:
89//!
90//! ```notrust
91//! RUSTFLAGS="--cfg hyper_unstable_tracing" cargo build
92//! ```
93//!
94//! [configuration flag]: https://doc.rust-lang.org/reference/conditional-compilation.html
95//!
96//! # Stability
97//!
98//! It's worth talking a bit about the stability of hyper. hyper's API follows
99//! [SemVer](https://semver.org). Breaking changes will only be introduced in
100//! major versions, if ever. New additions to the API, such as new types,
101//! methods, or traits will only be added in minor versions.
102//!
103//! Some parts of hyper are documented as NOT being part of the stable API. The
104//! following is a brief list, you can read more about each one in the relevant
105//! part of the documentation.
106//!
107//! - Downcasting error types from `Error::source()` is not considered stable.
108//! - Private dependencies use of global variables is not considered stable.
109//!   So, if a dependency uses `log` or `tracing`, hyper doesn't promise it
110//!   will continue to do so.
111//! - Behavior from default options is not stable. hyper reserves the right to
112//!   add new options that are enabled by default which might alter the
113//!   behavior, for the purposes of protection. It is also possible to _change_
114//!   what the default options are set to, also in efforts to protect the
115//!   most people possible.
116#[doc(hidden)]
117pub use http;
118
119#[cfg(all(test, feature = "nightly"))]
120extern crate test;
121
122#[doc(no_inline)]
123pub use http::{header, HeaderMap, Method, Request, Response, StatusCode, Uri, Version};
124
125pub use crate::error::{Error, Result};
126
127#[macro_use]
128mod cfg;
129
130#[macro_use]
131mod trace;
132
133pub mod body;
134mod common;
135mod error;
136pub mod ext;
137#[cfg(test)]
138mod mock;
139pub mod rt;
140pub mod service;
141pub mod upgrade;
142
143#[cfg(feature = "ffi")]
144#[cfg_attr(docsrs, doc(cfg(all(feature = "ffi", hyper_unstable_ffi))))]
145pub mod ffi;
146
147cfg_proto! {
148    mod headers;
149    mod proto;
150}
151
152cfg_feature! {
153    #![feature = "client"]
154
155    pub mod client;
156}
157
158cfg_feature! {
159    #![feature = "server"]
160
161    pub mod server;
162}