use barehttp::config::{ConfigBuilder, HttpStatusHandling, RedirectPolicy};
use barehttp::response::ResponseExt;
use barehttp::{Error, HttpClient};
use core::time::Duration;
fn main() -> Result<(), Error> {
println!("=== Configuration Examples ===\n");
println!("1. Client with custom timeout:");
let config = ConfigBuilder::new()
.timeout(Duration::from_secs(10))
.user_agent("barehttp-config-example/1.0")
.build();
let client = HttpClient::with_config(config)?;
let response = client.get("http://httpbin.org/delay/2").call()?;
println!("✓ Request completed with timeout setting");
println!("Status: {}\n", response.status_code);
println!("2. Client with no redirect following:");
let config = ConfigBuilder::new()
.redirect_policy(RedirectPolicy::NoFollow)
.build();
let client = HttpClient::with_config(config)?;
let response = client.get("http://httpbin.org/redirect/1").call()?;
println!("Status: {} (redirect not followed)", response.status_code);
if let Some(location) = response.get_header("Location") {
println!("Location header: {}\n", location);
}
println!("3. HTTP status codes as responses:");
let config = ConfigBuilder::new()
.http_status_handling(HttpStatusHandling::AsResponse)
.build();
let client = HttpClient::with_config(config)?;
let response = client.get("http://httpbin.org/status/404").call()?;
println!("Status: {} (returned as response, not error)", response.status_code);
println!("Is client error: {}\n", response.is_client_error());
println!("4. Limit maximum redirects:");
let config = ConfigBuilder::new()
.max_redirects(2)
.redirect_policy(RedirectPolicy::Follow)
.build();
let client = HttpClient::with_config(config)?;
let response = client.get("http://httpbin.org/redirect/1").call()?;
println!("✓ Followed redirect (max 2)");
println!("Final status: {}\n", response.status_code);
Ok(())
}