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
//! The HTTP layer underneath [`CanopyClient`](crate::CanopyClient).
//!
//! Everything above this layer (the wire types, the per-endpoint methods,
//! gzipping, status handling, JSON parsing) is transport-agnostic: this crate
//! does not decide how a request reaches canopy, and depends on no HTTP client.
//! A consumer implements [`CanopyTransport`] and keeps the whole typed interface
//! on top of it.
use Arc;
use Bytes;
use crateResult;
/// A request built by [`CanopyClient`](crate::CanopyClient), ready for a
/// [`CanopyTransport`] to send.
///
/// The URI is the endpoint **path** in origin form (path plus query, no scheme
/// or authority), e.g. `/backup-target` — resolving it against a base URL is the
/// transport's job. The body is already serialised and gzipped when there is one
/// (with `content-type` and `content-encoding` set to match) and empty when
/// there isn't.
pub type CanopyRequest = Request;
/// A response handed back to [`CanopyClient`](crate::CanopyClient) by a
/// [`CanopyTransport`], with its body buffered.
///
/// The status is interpreted by the client: a non-2xx becomes a
/// [`CanopyHttpError`](crate::CanopyHttpError) carrying the body, and a success
/// has its body parsed into the endpoint's response type.
pub type CanopyResponse = Response;
/// The HTTP transport a [`CanopyClient`](crate::CanopyClient) sends through.
///
/// Implement this to route canopy calls through whatever reaches canopy from
/// where you are — an mTLS client, a tailnet address, a proxy that isn't a plain
/// HTTP proxy, an in-process handler, a recorded fixture in tests — and pass it
/// to [`CanopyClient::new`](crate::CanopyClient::new). The per-endpoint methods,
/// the wire types, and the error handling all work unchanged on top.
///
/// # Contract
///
/// - Requests arrive with a path-only URI (see [`CanopyRequest`]); the transport
/// decides what host, scheme, and authentication to use, and may rewrite the
/// path.
/// - Return canopy's response as-is, non-2xx included: statuses are the client's
/// to interpret, since endpoints give meaning to specific codes.
/// - [`Err`] is for a failure to obtain any response at all (connect, timeout,
/// protocol error), which is distinct from a response reporting failure.