1
1
//! HTTP trailing headers.
2
- //!
2
+ //!
3
3
//! Trailing headers are headers that are send *after* the body payload has
4
4
//! been sent. This is for example useful for sending integrity checks of
5
5
//! streamed payloads that are computed on the fly.
6
- //!
6
+ //!
7
7
//! The way trailing headers are sent over the wire varies per protocol. But in
8
8
//! `http-types` we provide a `Trailers` struct that's used to contain the headers.
9
- //!
9
+ //!
10
10
//! To send trailing headers, see `Request::{`[`send_trailers, `][req_send]
11
11
//! [`recv_trailers`][req_recv]`}` and
12
12
//! `Response::{`[`send_trailers, `][res_send][`recv_trailers`][res_recv]`}`.
13
- //!
13
+ //!
14
14
//! [req_send]: ../struct.Request.html#method.send_trailers
15
15
//! [req_recv]: ../struct.Request.html#method.recv_trailers
16
16
//! [res_send]: ../struct.Response.html#method.send_trailers
17
17
//! [res_recv]: ../struct.Response.html#method.recv_trailers
18
- //!
18
+ //!
19
19
//! ## Example
20
- //!
20
+ //!
21
21
//! ```
22
22
//! # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
23
23
//! # async_std::task::block_on(async {
28
28
//! use std::str::FromStr;
29
29
//!
30
30
//! let mut req = Request::new(Method::Get, Url::parse("https://example.com").unwrap());
31
- //!
31
+ //!
32
32
//! let sender = req.send_trailers();
33
33
//! let mut trailers = Trailers::new();
34
34
//! trailers.insert(
35
35
//! HeaderName::from_str("Content-Type")?,
36
36
//! "text/plain",
37
37
//! );
38
- //!
38
+ //!
39
39
//! task::spawn(async move {
40
40
//! let _trailers = req.recv_trailers().await;
41
41
//! });
42
- //!
42
+ //!
43
43
//! sender.send(Ok(trailers)).await;
44
44
//! #
45
45
//! # Ok(()) })}
46
46
//! ```
47
- //!
47
+ //!
48
48
//! ## See Also
49
49
//! - [MDN HTTP Headers: Trailer](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer)
50
50
//! - [HTTP/2 spec: HTTP Sequence](https://http2.github.io/http2-spec/#HttpSequence)
51
51
52
- use async_std:: sync:: Sender ;
53
52
use crate :: headers:: {
54
53
HeaderName , HeaderValue , Headers , Iter , IterMut , Names , ToHeaderValues , Values ,
55
54
} ;
55
+ use async_std:: sync:: Sender ;
56
56
57
57
use std:: io;
58
58
use std:: ops:: { Deref , DerefMut } ;
@@ -150,7 +150,7 @@ impl DerefMut for Trailers {
150
150
}
151
151
152
152
/// The sending half of a channel to send trailers.
153
- ///
153
+ ///
154
154
/// Unlike `async_std::sync::channel` the `send` method on this type can only be
155
155
/// called once, and cannot be cloned. That's because only a single instance of
156
156
/// `Trailers` should be created.
@@ -166,7 +166,7 @@ impl TrailersSender {
166
166
}
167
167
168
168
/// Send a `Trailer`.
169
- ///
169
+ ///
170
170
/// The channel will be consumed after having sent trailers.
171
171
pub async fn send ( self , trailers : io:: Result < Trailers > ) {
172
172
self . sender . send ( trailers) . await
0 commit comments