product-os-request 0.0.55

Product OS : Request provides a fully featured HTTP request library combining elements of reqwest and hyper for async requests with a series of helper methods to allow for easier usage depending upon your needs for one-time or repeat usage.
Documentation
//! Tests for optional hyper features (timeout, cookies, compression)

#[cfg(all(feature = "std_hyper", feature = "hyper_timeout", feature = "json"))]
#[tokio::test]
async fn test_hyper_timeout() {
    use product_os_request::{Method, ProductOSClient, ProductOSHyperClient, ProductOSRequester};

    let mut requester = ProductOSRequester::new();
    // Set very short timeout (will likely timeout on slow connections)
    requester.set_timeout(1); // 1ms - very likely to timeout

    let mut client = ProductOSHyperClient::new();
    requester.build(&mut client);

    let request = client.new_request(Method::GET, "https://httpbin.org/delay/5");
    let response = client.request(request).await;

    // Should timeout
    assert!(response.is_err(), "Request should timeout");
    if let Err(e) = response {
        let error_msg = e.to_string();
        assert!(
            error_msg.contains("timeout") || error_msg.contains("timed out"),
            "Error should mention timeout: {}",
            error_msg
        );
    }
}

#[cfg(all(feature = "std_hyper", feature = "hyper_timeout", feature = "json"))]
#[tokio::test]
async fn test_hyper_no_timeout() {
    use product_os_request::{Method, ProductOSClient, ProductOSHyperClient, ProductOSRequester};

    let mut requester = ProductOSRequester::new();
    requester.set_timeout(5000); // 5 second timeout

    let mut client = ProductOSHyperClient::new();
    requester.build(&mut client);

    let request = client.new_request(Method::GET, "https://httpbin.org/get");
    let response = client.request(request).await;

    // Should succeed
    assert!(response.is_ok(), "Request should not timeout");
}

#[cfg(all(feature = "std_hyper", feature = "hyper_cookies", feature = "json"))]
#[tokio::test]
async fn test_hyper_cookies() {
    use product_os_request::{Method, ProductOSClient, ProductOSHyperClient, ProductOSRequester};

    let mut requester = ProductOSRequester::new();
    requester.set_timeout(5000);

    let mut client = ProductOSHyperClient::new();
    requester.build(&mut client);

    // Test that cookie feature is enabled and compiles
    // Full cookie functionality testing would require a test server that returns Set-Cookie headers
    let request = client.new_request(Method::GET, "https://httpbin.org/get");
    let response = client.request(request).await;

    assert!(
        response.is_ok(),
        "Request should succeed with cookie feature enabled"
    );
}

#[cfg(all(feature = "std_hyper", feature = "hyper_compression", feature = "json"))]
#[tokio::test]
async fn test_hyper_compression_headers() {
    use product_os_request::{Method, ProductOSClient, ProductOSHyperClient, ProductOSRequester};

    let mut requester = ProductOSRequester::new();
    requester.set_timeout(5000);

    let mut client = ProductOSHyperClient::new();
    requester.build(&mut client);

    // Test that compression feature is enabled and Accept-Encoding header is sent
    // Full compression/decompression would require more complex body handling
    let request = client.new_request(Method::GET, "https://httpbin.org/get");
    let response = client.request(request).await;

    assert!(
        response.is_ok(),
        "Request should succeed with compression feature enabled"
    );
    let response = response.unwrap();
    assert_eq!(response.status_code(), 200, "Status code should be 200");
}

#[cfg(all(feature = "std_hyper_full", feature = "json"))]
#[tokio::test]
async fn test_hyper_all_features() {
    use product_os_request::{
        Method, ProductOSClient, ProductOSHyperClient, ProductOSRequester, RedirectPolicy,
    };

    let mut requester = ProductOSRequester::new();
    requester.set_timeout(5000);
    requester.set_redirect_policy(RedirectPolicy::Limit(10));
    requester.add_header("X-Test-Header", "test-value", false);

    let mut client = ProductOSHyperClient::new();
    requester.build(&mut client);

    // Test with cookies, compression, timeout, and redirects all together
    let request = client.new_request(
        Method::GET,
        "https://httpbin.org/redirect-to?url=https://httpbin.org/cookies/set?fulltest=working",
    );
    let response = client.request(request).await;

    assert!(response.is_ok(), "Request with all features should succeed");
    let response = response.unwrap();
    assert_eq!(
        response.status_code(),
        200,
        "Should successfully follow redirect"
    );
}