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
// Copyright 2026 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! # SCION HTTP/3 client
//!
//! A high-level HTTP/3-over-SCION client: give it a URL, get a response.
//!
//! ## Features
//!
//! - SCION connectivity, discovered through an endhost API
//! - TSAR DNS resolution (SCION addresses from DNS TXT records)
//! - Per-origin connection pooling
//! - Staggered multi-candidate connection establishment ([RFC 8305], Happy Eyeballs)
//! - Connect, request, and idle-connection timeouts
//! - Recovery from network changes
//!
//! The transport engine underneath is [`scion_quic::h3::client::Http3Client`]. It stays
//! available for callers that need transport-level control.
//!
//! ## Usage
//!
//! Issue a GET request with the [`Client::get`] shorthand (see also [`Client::post`]):
//!
//! ```no_run
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! use scion_http3::{Client, Config};
//!
//! /// Cap on a collected response body.
//! const MAX_BODY_SIZE: usize = 1 << 20;
//!
//! let client = Client::new(
//! Config::new("https://endhost-api.example.org".parse()?).with_auth_token("token"),
//! );
//! let response = client.get("https://chat.example.org/rooms").await?;
//! let (rooms, _trailers) = response.text(Some(MAX_BODY_SIZE)).await?;
//! # Ok(())
//! # }
//! ```
//!
//! Or build a [`Request`] from scratch and issue it with [`Client::request`]:
//!
//! ```no_run
//! # async fn example(client: scion_http3::Client) -> Result<(), Box<dyn std::error::Error>> {
//! use scion_http3::Request;
//!
//! let request = Request::post("https://chat.example.org/messages")
//! .header("content-type", "application/json")
//! .body(r#"{"room":"general","text":"hi"}"#)
//! .build()?;
//! let response = client.request(request).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Tunnels
//!
//! [`Client::connect`] opens an HTTP `CONNECT` tunnel to an [`Authority`] (`host:port`). The
//! returned [`Tunnel`] is a byte stream that implements [`tokio::io::AsyncRead`] and
//! [`tokio::io::AsyncWrite`]:
//!
//! ```no_run
//! # async fn example(client: scion_http3::Client) -> Result<(), Box<dyn std::error::Error>> {
//! use scion_http3::Authority;
//! use tokio::io::{AsyncReadExt, AsyncWriteExt};
//!
//! let authority: Authority = "chat.example.org:443".parse()?;
//! let mut tunnel = client.connect(&authority).await?;
//! tunnel.write_all(b"hello").await?;
//! let mut reply = vec![0u8; 5];
//! tunnel.read_exact(&mut reply).await?;
//! tunnel.shutdown().await?;
//! # Ok(())
//! # }
//! ```
//!
//! The authority's host is resolved like a URL's host. [`Config::with_dns_override`] maps a
//! host that has no TSAR records to fixed addresses.
//!
//! ## Connection pooling and lifecycle
//!
//! A [`Client`] holds a connection pool, so create one client per application and share it.
//!
//! Construction does no I/O: connections are established lazily on first use and then reused
//! per origin. Use [`Client::warm_up`] to establish a connection before the first request.
//!
//! [`Client::close`] closes all pooled connections and frees their resources. Calling it
//! before dropping the client is optional.
//!
//! ## Network changes
//!
//! Call [`Client::reset`] when the network below the client changes, for example when the
//! platform reports a switch from Wi-Fi to mobile data. The call never blocks: it marks the
//! current connections stale, and the next request tears them down and rebuilds connectivity.
//!
//! ## Error handling
//!
//! Every request-path failure surfaces as one error type, [`Error`]. To decide whether to
//! retry a failed request, use [`Error::is_retryable`] instead of matching variants.
//! A retryable error does not imply the request never reached the server, so retry
//! non-idempotent requests with care.
//!
//! [RFC 8305]: https://datatracker.ietf.org/doc/html/rfc8305
// Linter baseline for the published API surface.
// Re-exported dependencies
//
// These crates appear in `scion-http3`'s public API by deliberate choice. They are re-exported
// here so a client can name and construct the types our signatures require without adding
// its own direct dependency.
pub use ApiKeyAuth;
/// Body bytes ([`bytes::Bytes`]) used for request bodies and collected response bodies.
pub use ;
pub use bytes;
pub use Client;
pub use ;
pub use ;
/// HTTP vocabulary types ([`http::Method`], [`http::HeaderMap`], [`http::StatusCode`]) used by
/// requests and responses.
pub use http;
pub use ;
pub use Response;
/// The transport engine. Its types appear in this API as the QUIC configuration
/// ([`scion_quic::quic::config::QuicConfig`], see [`Config::with_quic_config`]).
pub use scion_quic;
/// The SCION stack. Its types appear in this API as the builder passthroughs
/// ([`Config::with_preferred_underlay`], [`Config::with_stack_customizer`]) and the resolver
/// escape hatch ([`Config::with_resolver`]).
pub use scion_stack;
/// Authentication token plumbing for [`Config::with_auth_token_source`]: implement
/// [`TokenSource`] to supply tokens that expire; [`StaticTokenSource`] wraps a fixed one.
/// [`Config::with_api_key`] builds a source that exchanges an Anapaya AA API key for tokens
/// itself.
pub use ;
/// SCION address types ([`sciparse::address::ip_addr::ScionIpAddr`]) used by
/// [`Config::with_dns_override`].
pub use sciparse;
/// Async I/O traits ([`tokio::io::AsyncRead`], [`tokio::io::AsyncWrite`]) implemented by
/// [`Tunnel`].
pub use tokio;
pub use Tunnel;
/// URL type used for request URLs and the endhost API address.
pub use url;