nautilus_network/http/mod.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Asynchronous HTTP requests with rate limiting, connection reuse, and bounded responses.
17//!
18//! # Architecture
19//!
20//! [`HttpClient`] applies quota policy before delegating requests to [`InnerHttpClient`]. The inner
21//! client owns one reusable Hyper client, preserving its connection pool across requests and clones.
22//!
23//! # Rate limiting and requests
24//!
25//! Requests can await default and per-key quotas from one or more shared
26//! [`RateLimiter`](crate::ratelimiter::RateLimiter) instances. Sharing a limiter across clients
27//! enforces one process-wide budget for scopes such as an IP address or account. The client accepts
28//! default and per-request headers, repeated query values, raw bodies, client-level and per-request
29//! timeouts, and an optional proxy.
30//!
31//! HTTP status errors remain [`HttpResponse`] values for adapter-specific handling. The transport
32//! retries requests canceled before transmission on reused connections, and allows two retries for
33//! remote HTTP/2 `GOAWAY(NO_ERROR)` or `REFUSED_STREAM` errors. Other transport failures and HTTP
34//! status codes do not trigger retries. Adapters can apply [`crate::retry::RetryManager`] when the
35//! operation and venue error are safe to retry.
36//!
37//! # Connection and response policy
38//!
39//! Production clients built through [`HttpClient::builder`] enable `TCP_NODELAY`, pooled idle
40//! connections, HTTP/2 keepalive while idle, and adaptive HTTP/2 flow control. Buffered responses
41//! retain only configured header fields and reject bodies larger than 100 MiB, including chunked
42//! bodies without a declared length. [`HttpClient::get_stream`] consumes bodies incrementally
43//! without a total size limit. The redacted request path removes credential-bearing URLs from
44//! transport errors and logs.
45//!
46//! Hyper owns the lifecycle of individual pooled connections, so this client exposes no socket
47//! state sink or explicit reconnect operation. Callers observe connection failure through each
48//! request result and retain the client to preserve its pool.
49
50pub mod client;
51pub mod error;
52pub mod types;
53
54#[cfg(not(all(feature = "simulation", madsim)))]
55mod connector;
56#[cfg(all(feature = "simulation", madsim))]
57mod simulation;
58#[cfg(not(all(feature = "simulation", madsim)))]
59mod transport;
60
61mod stream;
62
63// Re-exports
64pub use client::{HttpClient, HttpRedirectPolicy, InnerHttpClient};
65pub use error::HttpClientError;
66pub use http::{Method, StatusCode, header::USER_AGENT};
67pub use stream::HttpResponseStream;
68pub use types::{HttpMethod, HttpResponse, HttpStatus};
69pub use url::Url;
70
71#[cfg(all(test, not(all(feature = "simulation", madsim))))]
72mod tests;