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.mddocs/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§
- Auth
Param - A single auth-param pair parsed from a challenge.
- Challenge
- Parsed authentication challenge.
- Client
- Reusable synchronous HTTP client.
- Client
Builder - Builder for configuring a
Client. - Header
- A single HTTP header field.
- Proxy
Config - Proxy configuration for routing requests through an HTTP proxy.
- Request
- A typed HTTP request for
GETorHEAD. - 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§
- Auth
Decision - Authentication handler result for a challenge set.
- Auth
Target - Indicates which authentication space a challenge belongs to.
- Cache
Mode - Controls whether the built-in in-memory cache is used.
- Connection
Policy - Controls whether requests use one-off sockets or reusable persistent connections.
- Http
Version - HTTP protocol version reported by the server response line.
- Method
- Supported request methods.
- Nano
GetError - Error type for all fallible operations in this crate.
- Parser
Strictness - Controls how strictly incoming HTTP/1.1 responses are parsed.
- Redirect
Policy - Redirect behavior for a request.
Traits§
- Auth
Handler - Callback interface for custom authentication schemes.
- ToUrl
- Conversion trait for values that can be parsed into a
Url.
Functions§
- get
- Performs a
GETrequest and returns the response body as UTF-8 text. - get_
bytes - Performs a
GETrequest and returns the response body as raw bytes. - get_
http - Performs a
GETrequest using HTTP only and returns UTF-8 text. - get_
http_ bytes - Performs a
GETrequest using HTTP only and returns raw bytes. - head
- Performs a
HEADrequest and returns the full response metadata. - head_
http - Performs a
HEADrequest using HTTP only.