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
//! Cross-platform HTTP client with native backend support
//!
//! This crate provides a unified async HTTP client that automatically selects
//! the best backend for your platform. On Apple platforms, it uses NSURLSession
//! for native performance and iOS background downloads. On other platforms,
//! it uses reqwest with additional features like daemon processes for
//! background downloads on Unix systems.
//!
//! # Features
//!
//! - **Async-only design**: Built from the ground up for async/await with tokio
//! - **HTTP client**: Full-featured HTTP client with support for all standard methods
//! - **File downloads**: Efficient streaming downloads directly to disk with progress tracking
//! - **File uploads**: Support for uploading files or data with progress tracking
//! - **Background downloads**: Platform-specific background downloads (NSURLSession on Apple, daemon processes on Unix)
//! - **WebSocket support**: Native WebSocket connections (NSURLSessionWebSocketTask on Apple, tokio-tungstenite elsewhere)
//! - **Cookie management**: Automatic cookie handling with custom cookie jar support
//! - **Authentication**: Built-in support for Bearer, Basic, and custom authentication
//! - **Proxy support**: HTTP, HTTPS, and SOCKS proxy configuration
//! - **TLS configuration**: Certificate validation control and custom TLS settings
//! - **Request/Response body streaming**: Memory-efficient handling of large payloads
//! - **Multipart uploads**: Support for multipart/form-data uploads (with `multipart` feature)
//!
//! # Quick Start
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! frakt = "0.1"
//! tokio = { version = "1.0", features = ["full"] }
//! ```
//!
//! ## Basic HTTP Request
//!
//! ```rust,no_run
//! use frakt::Client;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::new()?;
//!
//! let response = client
//! .get("https://httpbin.org/json")?
//! .header(http::header::ACCEPT, "application/json")?
//! .send()
//! .await?;
//!
//! println!("Status: {}", response.status());
//! let body = response.text().await?;
//! println!("Response: {}", body);
//!
//! Ok(())
//! }
//! ```
//!
//! ## File Download with Progress
//!
//! ```rust,no_run
//! use frakt::Client;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::new()?;
//!
//! let response = client
//! .download("https://example.com/large-file.zip")?
//! .to_file("./downloads/file.zip")
//! .progress(|downloaded, total| {
//! if let Some(total) = total {
//! let percent = (downloaded as f64 / total as f64) * 100.0;
//! println!("Downloaded: {:.1}%", percent);
//! }
//! })
//! .send()
//! .await?;
//!
//! println!("Downloaded {} bytes to {}",
//! response.bytes_downloaded,
//! response.file_path.display());
//!
//! Ok(())
//! }
//! ```
//!
//! ## File Upload
//!
//! ```rust,no_run
//! use frakt::Client;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::new()?;
//!
//! let response = client
//! .upload("https://httpbin.org/post")?
//! .from_file("./upload.txt")
//! .header(http::header::CONTENT_TYPE, "text/plain")?
//! .progress(|uploaded, total| {
//! if let Some(total) = total {
//! let percent = (uploaded as f64 / total as f64) * 100.0;
//! println!("Uploaded: {:.1}%", percent);
//! }
//! })
//! .send()
//! .await?;
//!
//! println!("Upload completed with status: {}", response.status());
//!
//! Ok(())
//! }
//! ```
//!
//! ## WebSocket Connection
//!
//! ```rust,no_run
//! use frakt::{Client, Message, CloseCode};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::new()?;
//!
//! let mut websocket = client
//! .websocket()
//! .connect("wss://echo.websocket.org")
//! .await?;
//!
//! // Send a message
//! websocket.send(Message::text("Hello, WebSocket!")).await?;
//!
//! // Receive a message
//! let message = websocket.receive().await?;
//! println!("Received: {:?}", message);
//!
//! // Close the connection
//! websocket.close(CloseCode::Normal, Some("Goodbye"));
//!
//! Ok(())
//! }
//! ```
//!
//! ## Background Downloads
//!
//! Background downloads continue even when your app is suspended or terminated.
//! The implementation varies by platform:
//! - **Apple platforms**: Uses NSURLSession background downloads
//! - **Unix systems**: Uses daemon processes for true background operation
//! - **Other platforms**: Uses resumable downloads with retry logic
//!
//! ```rust,no_run
//! use frakt::Client;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::new()?;
//!
//! let response = client
//! .download_background("https://example.com/large-video.mp4")
//! .session_identifier("com.myapp.downloads")
//! .to_file("./downloads/video.mp4")
//! .progress(|downloaded, total| {
//! if let Some(total) = total {
//! let percent = (downloaded as f64 / total as f64) * 100.0;
//! println!("Background download: {:.1}%", percent);
//! }
//! })
//! .send()
//! .await?;
//!
//! println!("Background download completed: {}", response.file_path.display());
//!
//! Ok(())
//! }
//! ```
//!
//! ## Client Configuration
//!
//! ```rust,no_run
//! use frakt::Client;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = Client::builder()
//! .user_agent("MyApp/1.0")
//! .timeout(Duration::from_secs(30))
//! .use_cookies(true)
//! .header("X-API-Version", "v1")?
//! .build()?;
//!
//! let response = client
//! .get("https://api.example.com/data")?
//! .send()
//! .await?;
//!
//! Ok(())
//! }
//! ```
//!
//! # Platform Support
//!
//! This crate supports multiple platforms through a backend abstraction:
//!
//! - **Apple platforms** (macOS, iOS, tvOS, watchOS): Uses NSURLSession for native performance and iOS background downloads
//! - **Other platforms**: Uses reqwest with platform-specific enhancements:
//! - **Unix systems**: Daemon processes for true background downloads
//! - **All platforms**: Resumable downloads with retry logic
//!
//! # Performance
//!
//! **Apple platforms** benefit from NSURLSession's optimized networking stack:
//! - HTTP/2 and HTTP/3 support
//! - Connection pooling and reuse
//! - Automatic compression (gzip, deflate)
//! - Network quality-of-service (QoS) handling
//! - Cellular and Wi-Fi network management
//! - True background transfer capabilities
//!
//! **Other platforms** use reqwest with additional features:
//! - HTTP/2 support via reqwest
//! - Connection pooling and keep-alive
//! - Automatic decompression
//! - Background downloads via daemon processes (Unix) or resumable downloads
// Multi-platform support via backend abstraction
pub use Auth;
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export body types
pub use Body;
pub use MultipartPart;
pub use ;
pub use ;
// Re-export http types for convenience
pub use http;