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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
use Duration;
use async_trait;
use crateRedacted;
use crateTransportError;
/// Successful HTTP response captured by an [`HttpTransport`] implementation.
///
/// Carries the numeric status code, the response headers, and the response
/// body of a 2xx dispatch — the same field set
/// [`TransportError::HttpStatus`] already carries for non-2xx responses, so
/// one representation spans the success and failure channels. Accessor names
/// mirror `http::Response` (`status`, `headers`, `into_body`) so a later
/// migration onto `http` types is a mechanical rename rather than a
/// redesign. Fields stay private so the representation can evolve behind the
/// accessors.
///
/// Header values are wrapped in [`Redacted`]: response header sections can
/// carry `Set-Cookie` or gateway-injected credentials, so values never
/// render through `Debug`. The body is the payload the caller requested and
/// is exposed raw through [`TransportResponse::body`]; the [`std::fmt::Debug`]
/// implementation prints only its byte length.
///
/// Implementations construct a value only for 2xx responses; non-2xx
/// responses keep flowing through [`TransportError::HttpStatus`]. On browser
/// targets, cross-origin header visibility is bounded by CORS exposure:
/// `Content-Type` and the other safelisted names are always readable, while
/// anything else requires the server to opt in through
/// `Access-Control-Expose-Headers`.
/// Production injection point for HTTPS REST transport.
///
/// Implementations dispatch REST requests without committing the calling
/// crate to any specific backend. The native default implementation is
/// [`ReqwestTransport`](crate::transport::ReqwestTransport); the browser
/// default implementation is `FetchTransport`, the `wasm32` sibling in this
/// crate's `transport::fetch` module, which bridges the same async signature
/// through `JsFuture`.
///
/// Most consumers never implement this trait. The orderbook and subgraph
/// builders install the per-target default automatically, so the zero-config
/// `.build()` path serves native and browser callers alike. Common tuning does
/// not require a custom transport either: reuse a pre-configured
/// `reqwest::Client` (proxy, custom TLS, connection pool) through the native
/// builder's `.client(..)` seam, supply credentials through `.api_key(..)` and
/// the per-call header set, and shape retry, rate limiting, timeout, and
/// user-agent through `TransportPolicy`. Implementing this trait is the
/// deliberate escape hatch for three cases: a JavaScript host supplying its own
/// `fetch` or callback (see `cow_sdk_js::exports::JsCallbackHttpTransport`),
/// test doubles that record or replay requests, and wrapping an inner transport
/// to add caching or other middleware. The `Arc<dyn HttpTransport>` seam is what
/// keeps those injectable at runtime.
///
/// This trait does not retry. Retry, jitter, rate limiting, and
/// `Retry-After` handling are applied at the orderbook layer via
/// `cow_sdk_core::transport::policy::TransportPolicy`. See `docs/guides/transport.md`.
///
/// Every method carries the per-call header set and an optional per-call
/// timeout alongside the URL and body so downstream crates compose typed
/// clients without holding a parallel `reqwest::Client` for header or
/// deadline overrides. Implementations merge per-call headers with any
/// constructor-configured defaults, honor the per-call timeout when `Some`,
/// and map non-2xx responses into
/// [`TransportError::HttpStatus`]
/// so the calling layer receives the numeric status, response headers, and
/// raw body through the typed error channel. The success channel carries the
/// same fidelity: `Ok` returns a [`TransportResponse`] with the 2xx status
/// code, the response headers, and the body, so calling layers never have to
/// fabricate response metadata.
///
/// The trait uses [`macro@async_trait`] so downstream clients can hold the
/// transport behind `Arc<dyn HttpTransport + Send + Sync>` without reaching for a
/// bespoke adapter trait. Implementations carry [`std::fmt::Debug`] so
/// trait objects render in derived `Debug` output of consumer-facing
/// clients without bespoke formatters. On native targets the returned
/// futures are `Send` so downstream crates compose them onto
/// multi-threaded runtimes; on `wasm32` targets the futures drop the
/// `Send` bound so the browser adapter remains viable.
///
/// # Implementing
///
/// The transport is held behind `Arc<dyn HttpTransport>`, so an implementor
/// annotates the `impl` with the re-exported
/// [`async_trait`](macro@async_trait). `cow-sdk-core` re-exports the macro, so
/// an out-of-tree implementor does not declare an `async-trait` dependency
/// itself:
///
/// ```
/// use std::time::Duration;
/// use cow_sdk_core::{async_trait, HttpTransport, TransportError, TransportResponse};
///
/// #[derive(Debug)]
/// struct MyTransport;
///
/// #[cfg_attr(not(target_arch = "wasm32"), async_trait)]
/// #[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
/// impl HttpTransport for MyTransport {
/// async fn get(
/// &self,
/// path: &str,
/// headers: &[(String, String)],
/// timeout: Option<Duration>,
/// ) -> Result<TransportResponse, TransportError> {
/// todo!("dispatch the GET through your HTTP backend")
/// }
/// async fn post(
/// &self,
/// path: &str,
/// body: &str,
/// headers: &[(String, String)],
/// timeout: Option<Duration>,
/// ) -> Result<TransportResponse, TransportError> {
/// todo!()
/// }
/// async fn put(
/// &self,
/// path: &str,
/// body: &str,
/// headers: &[(String, String)],
/// timeout: Option<Duration>,
/// ) -> Result<TransportResponse, TransportError> {
/// todo!()
/// }
/// async fn delete(
/// &self,
/// path: &str,
/// body: &str,
/// headers: &[(String, String)],
/// timeout: Option<Duration>,
/// ) -> Result<TransportResponse, TransportError> {
/// todo!()
/// }
/// }
/// ```