1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/// HTTP protocol preference for HTTP(S) requests.
///
/// For HTTPS, `Auto` advertises HTTP/2 and HTTP/1.1 through TLS ALPN and lets
/// the server select the protocol. It falls back to HTTP/1.1 when HTTP/2 is
/// not negotiated. Plain HTTP uses the client's default HTTP/1 behavior; the
/// explicit variants are strict selections.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum HttpVersion {
/// Prefer HTTP/2 and negotiate HTTP/1.1 when HTTP/2 is unavailable.
#[default]
Auto,
/// Force HTTP/1.1.
Http11,
/// Force HTTP/2.
Http2,
}
impl HttpVersion {
/// Parse the public `--http-version` option values.
pub fn parse_option(value: &str) -> Option<Self> {
match value {
"auto" => Some(Self::Auto),
"1.1" => Some(Self::Http11),
"2" => Some(Self::Http2),
_ => None,
}
}
/// Return the canonical public option value.
pub const fn option_value(self) -> &'static str {
match self {
Self::Auto => "auto",
Self::Http11 => "1.1",
Self::Http2 => "2",
}
}
pub(crate) fn configure(self, builder: reqwest::ClientBuilder) -> reqwest::ClientBuilder {
match self {
Self::Auto => builder,
Self::Http11 => builder.http1_only(),
Self::Http2 => builder.http2_prior_knowledge(),
}
}
}