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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! HTTP transport abstraction for network-derived identity sources.
//!
//! Built-in cloud sources (e.g. [`crate::sources::AwsImds`]) are generic over
//! a transport the consumer provides. The crate ships no HTTP client of its
//! own — picking one (sync, async, TLS backend, connection pool, …) is the
//! consumer's call.
//!
//! Adapt an existing client by implementing [`HttpTransport`] on a newtype,
//! or pass a closure — a blanket impl accepts any
//! `Fn(Request) -> Result<Response, _>`.
//!
//! ```
//! # #[cfg(feature = "_transport")] fn compile_check() {
//! use host_identity::transport::HttpTransport;
//!
//! // Stand-in types — a real adapter uses ureq / reqwest / hyper.
//! struct MyClient;
//! #[derive(Debug)]
//! struct MyError;
//! impl std::fmt::Display for MyError {
//! fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
//! f.write_str("my transport error")
//! }
//! }
//! impl std::error::Error for MyError {}
//!
//! impl HttpTransport for MyClient {
//! type Error = MyError;
//! fn send(
//! &self,
//! _request: http::Request<Vec<u8>>,
//! ) -> Result<http::Response<Vec<u8>>, Self::Error> {
//! // In a real impl: translate http::Request to your client's
//! // request type, perform the call, translate the response
//! // back. The crate's cloud sources pass the request in
//! // populated; you translate bytes both ways and surface
//! // network/TLS/timeout errors as `Err`.
//! Ok(http::Response::builder()
//! .status(200)
//! .body(b"example-id".to_vec())
//! .unwrap())
//! }
//! }
//! # }
//! ```
/// Synchronous HTTP transport.
///
/// The library owns the protocol (URLs, headers, response parsing); the
/// transport only moves bytes. Async clients are supported by wrapping their
/// call in `block_on` inside [`HttpTransport::send`].
/// Blanket impl so any `Fn(Request) -> Result<Response, E>` is a transport.