Skip to main content

Crate nano_get

Crate nano_get 

Source
Expand description

A tiny HTTP/1.1 client for GET and HEAD.

The default build has zero external dependencies. Enable the https feature flag to add HTTPS support via the system OpenSSL library.

§Compliance Scope

The crate’s compliance claim covers all client-applicable RFC 9110, RFC 9111, and RFC 9112 requirements for an HTTP/1.1 GET/HEAD user agent, within the documented claim boundary.

Auditable artifacts in the repository:

  • docs/compliance/http11-get-head-rfc-matrix.md
  • docs/compliance/http11-get-head-requirement-test-index.md

§Helper API

let body = nano_get::get("http://example.com")?;

§Advanced API

let client = nano_get::Client::builder()
    .connection_policy(nano_get::ConnectionPolicy::Reuse)
    .cache_mode(nano_get::CacheMode::Memory)
    .basic_auth("user", "pass")
    .build();
let response = client.execute(
    nano_get::Request::get("http://example.com")?
        .with_redirect_policy(nano_get::RedirectPolicy::follow(5)),
)?;
assert!(response.status_code >= 200);

§Custom Authentication

use std::sync::Arc;

struct TokenAuth;

impl nano_get::AuthHandler for TokenAuth {
    fn respond(
        &self,
        _target: nano_get::AuthTarget,
        _url: &nano_get::Url,
        challenges: &[nano_get::Challenge],
        _request: &nano_get::Request,
        _response: &nano_get::Response,
    ) -> Result<nano_get::AuthDecision, nano_get::NanoGetError> {
        if challenges
            .iter()
            .any(|challenge| challenge.scheme.eq_ignore_ascii_case("token"))
        {
            return Ok(nano_get::AuthDecision::UseHeaders(vec![
                nano_get::Header::new("Authorization", "Token secret")?,
            ]));
        }

        Ok(nano_get::AuthDecision::NoMatch)
    }
}

let client = nano_get::Client::builder()
    .auth_handler(Arc::new(TokenAuth))
    .build();
let response = client.execute(nano_get::Request::get("http://example.com/protected")?)?;
assert!(response.status_code >= 200);

Structs§

AuthParam
A single auth-param pair parsed from a challenge.
Challenge
Parsed authentication challenge.
Client
Reusable synchronous HTTP client.
ClientBuilder
Builder for configuring a Client.
Header
A single HTTP header field.
ProxyConfig
Proxy configuration for routing requests through an HTTP proxy.
Request
A typed HTTP request for GET or HEAD.
Response
Parsed HTTP response data.
Session
Stateful request executor that can hold a persistent connection.
Url
Parsed URL data used by request builders and transports.

Enums§

AuthDecision
Authentication handler result for a challenge set.
AuthTarget
Indicates which authentication space a challenge belongs to.
CacheMode
Controls whether the built-in in-memory cache is used.
ConnectionPolicy
Controls whether requests use one-off sockets or reusable persistent connections.
HttpVersion
HTTP protocol version reported by the server response line.
Method
Supported request methods.
NanoGetError
Error type for all fallible operations in this crate.
ParserStrictness
Controls how strictly incoming HTTP/1.1 responses are parsed.
RedirectPolicy
Redirect behavior for a request.

Traits§

AuthHandler
Callback interface for custom authentication schemes.
ToUrl
Conversion trait for values that can be parsed into a Url.

Functions§

get
Performs a GET request and returns the response body as UTF-8 text.
get_bytes
Performs a GET request and returns the response body as raw bytes.
get_http
Performs a GET request using HTTP only and returns UTF-8 text.
get_http_bytes
Performs a GET request using HTTP only and returns raw bytes.
head
Performs a HEAD request and returns the full response metadata.
head_http
Performs a HEAD request using HTTP only.