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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
//! # barehttp
//!
//! **A minimal, explicit HTTP client for Rust**
//!
//! barehttp is a low-level, blocking HTTP client designed for developers who want
//! **predictable behavior, full control, and minimal dependencies**.
//!
//! It supports `no_std` (with `alloc`), avoids global state, and exposes all network
//! behavior explicitly. There is no async runtime, no hidden connection pooling,
//! and no built-in TLS—you bring your own via adapters.
//!
//! ## Key Features
//!
//! - **Minimal and explicit**: No global state, no implicit behavior
//! - **`no_std` compatible**: Core works with `alloc` only
//! - **Blocking I/O**: Simple, predictable execution model
//! - **Generic adapters**: Custom socket and DNS implementations
//! - **Compile-time safety**: Typestate enforces correct body usage
//!
//! ## Quick Start
//!
//! ```no_run
//! use barehttp::response::ResponseExt;
//!
//! let response = barehttp::get("http://httpbin.org/get")?;
//! let body = response.text()?;
//! println!("{}", body);
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ## Using `HttpClient`
//!
//! For repeated requests or more control, use [`HttpClient`]:
//!
//! ```no_run
//! use barehttp::HttpClient;
//! use barehttp::response::ResponseExt;
//!
//! let mut client = HttpClient::new()?;
//!
//! let response = client
//! .get("http://httpbin.org/get")
//! .header("User-Agent", "my-app/1.0")
//! .call()?;
//!
//! println!("Status: {}", response.status_code);
//! println!("Body: {}", response.text()?);
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ## Configuration
//!
//! Client behavior is controlled via [`config::Config`] and [`config::ConfigBuilder`]:
//!
//! ```no_run
//! use barehttp::HttpClient;
//! use barehttp::config::ConfigBuilder;
//! use core::time::Duration;
//!
//! let config = ConfigBuilder::new()
//! .timeout(Duration::from_secs(30))
//! .max_redirects(5)
//! .user_agent("my-app/2.0")
//! .build();
//!
//! let mut client = HttpClient::with_config(config)?;
//!
//! let response = client.get("http://httpbin.org/get").call()?;
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ## Making Requests
//!
//! ### GET
//!
//! ```no_run
//! let mut client = barehttp::HttpClient::new()?;
//!
//! let response = client.get("http://httpbin.org/get").call()?;
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ### POST with body
//!
//! ```no_run
//! let mut client = barehttp::HttpClient::new()?;
//!
//! let response = client
//! .post("http://httpbin.org/post")
//! .header("Content-Type", "application/json")
//! .send(br#"{"name":"test"}"#.to_vec())?;
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ## Type-Safe Request Bodies
//!
//! Request methods enforce body semantics at compile time:
//!
//! - GET, HEAD, DELETE, OPTIONS → methods without body
//! - POST, PUT, PATCH → methods with body
//!
//! ```compile_fail
//! let mut client = barehttp::HttpClient::new()?;
//! client.get("http://example.com").send(vec![])?;
//! ```
//!
//! ```no_run
//! let mut client = barehttp::HttpClient::new()?;
//! client.post("http://example.com").send(b"data".to_vec())?;
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ## Error Handling
//!
//! All operations return `Result<T, barehttp::Error>`.
//!
//! Errors include:
//! - DNS resolution failures
//! - Socket I/O errors
//! - Parse errors
//! - HTTP status errors (4xx/5xx by default)
//!
//! ```no_run
//! use barehttp::{Error, HttpClient};
//!
//! let mut client = HttpClient::new()?;
//!
//! match client.get("http://httpbin.org/status/404").call() {
//! Ok(resp) => println!("Status: {}", resp.status_code),
//! Err(Error::HttpStatus(code)) => println!("HTTP error: {}", code),
//! Err(e) => println!("Other error: {:?}", e),
//! }
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! Automatic HTTP status errors can be disabled via configuration.
//!
//! ## Response Helpers
//!
//! The [`response::ResponseExt`] trait provides helpers for common tasks:
//!
//! ```no_run
//! use barehttp::response::ResponseExt;
//!
//! let mut client = barehttp::HttpClient::new()?;
//! let response = client.get("http://httpbin.org/get").call()?;
//!
//! if response.is_success() {
//! let text = response.text()?;
//! println!("{}", text);
//! }
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ## Custom Socket and DNS Adapters
//!
//! barehttp’s networking is fully pluggable.
//!
//! Implement `BlockingSocket` and `DnsResolver` traits to provide:
//!
//! - TLS via external libraries
//! - Proxies or tunnels
//! - Embedded or WASM networking
//! - Test mocks
//!
//! ```no_run
//! use barehttp::{HttpClient, OsBlockingSocket, OsDnsResolver};
//!
//! let dns = OsDnsResolver::new();
//! let mut client: HttpClient<OsBlockingSocket, _> = HttpClient::new_with_adapters(dns);
//! let response = client.get("http://example.com").call()?;
//! # Ok::<(), barehttp::Error>(())
//! ```
//!
//! ## Design Notes
//!
//! - Blocking I/O keeps the API simple and dependency-free
//! - Each request is independent and explicit
//! - No shared state or background behavior
//!
//! barehttp is intended for environments where **clarity and control matter more than convenience**.
extern crate alloc;
/// RFC 6265 compliant cookie storage and management
///
/// This module provides a `CookieStore` for automatic cookie handling
/// in HTTP requests and responses, including domain/path matching and expiration.
// Re-exports of core types
pub use HttpClient;
pub use Error;
pub use IntoBody;
// Re-exports of default OS adapters
pub use OsDnsResolver;
pub use OsBlockingSocket;
// Re-exports of request/response types
pub use Body;
pub use ;
pub use Method;
pub use ;
pub use Version;
pub use Request;
// Convenience functions for quick HTTP requests
/// Convenience function for GET requests
///
/// Creates a new client with default OS adapters and executes a GET request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for POST requests
///
/// Creates a new client with default OS adapters and executes a POST request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for PUT requests
///
/// Creates a new client with default OS adapters and executes a PUT request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for DELETE requests
///
/// Creates a new client with default OS adapters and executes a DELETE request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for HEAD requests
///
/// Creates a new client with default OS adapters and executes a HEAD request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for OPTIONS requests
///
/// Creates a new client with default OS adapters and executes an OPTIONS request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for PATCH requests
///
/// Creates a new client with default OS adapters and executes a PATCH request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for TRACE requests
///
/// Creates a new client with default OS adapters and executes a TRACE request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
/// Convenience function for CONNECT requests
///
/// Creates a new client with default OS adapters and executes a CONNECT request.
///
/// # Errors
/// Returns an error if URL parsing, DNS resolution, socket connection, or HTTP communication fails.
// Public modules
/// Configuration for HTTP client behavior
/// Typestate request builder for compile-time safety
/// Response extensions and helpers
pub
pub
pub