gosub-sonar
Browser-agnostic priority-scheduled HTTP/HTTPS fetching library.
Overview
gosub-sonar provides two fetching APIs:
simple_get— one-shot GET for tools and scripts that just need bytes.Fetcher— full priority scheduler with request coalescing, per-origin concurrency limits, and fan-out to multiple subscribers.
The library has no dependency on any browser engine and can be used standalone.
Usage
Add to your Cargo.toml (the scheduler API also uses these companion crates directly):
[]
= "0.2"
= "1"
= { = "1", = ["rt", "macros"] }
= "0.7"
= "2"
One-shot GET
use simple_get;
use Url;
let bytes = simple_get.await?;
Priority scheduler
use Arc;
use ;
use Method;
use CancellationToken;
use Url;
// NullContext ignores all lifecycle events; implement FetcherContext to receive them.
let fetcher = new;
let shutdown = new;
let f = fetcher.clone;
let cancel = shutdown.clone;
spawn;
let req = builder
.with_priority
.with_auto_decode
.build;
match fetcher.fetch.await
shutdown.cancel;
For per-subscriber cancellation use fetcher.fetch_with_cancel(req, token); for full control
over the reply channel use fetcher.submit(req, cancel, reply_tx).
See the examples/ directory for runnable versions.
HSTS
HTTP Strict Transport Security (RFC 6797) is on by default: a site that sends
Strict-Transport-Security over HTTPS is recorded, and later http:// requests to it are
rewritten to https:// before any connection is opened. The default store is in-memory, so
policies last for the life of the process and need no setup.
To persist across restarts, implement HstsStore — a host-keyed map. The crate handles max-age,
includeSubDomains matching, and expiry, so the store interprets nothing:
use ;
let cfg = FetcherConfig ;
load runs on every hop of every request, so it must not block — keep an in-memory map and
persist in the background.
Set hsts: None to disable HSTS: nothing consulted, nothing recorded. This is what a
private-browsing session wants.
There is no preload list. On wasm32 the browser's fetch() applies its own HSTS, so the field does
not exist there.
Proxies
By default the fetcher reads HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, and NO_PROXY from the
environment. FetcherConfig::proxy replaces that with your own settings:
use ;
let cfg = FetcherConfig ;
Rules are matched in order; each carries a scope (http, https, or all), optional credentials,
and an optional NO_PROXY-syntax bypass list. Anything other than ProxyConfig::System ignores
the environment entirely, so ProxyConfig::Disabled guarantees a direct connection. socks4,
socks5, and socks5h proxy URLs need the socks feature. On wasm32 the browser's fetch()
uses the user's own proxy settings, so the field does not exist there.
Examples
cargo run --example simple_fetch -- https://example.org
cargo run --example fetcher -- https://example.org
cargo run --example fetcher_harness --features test-support
Documentation
API documentation is available on docs.rs. Design notes live
in the docs/ directory:
- architecture.md — overall structure of the fetch stack
- net-design.md — scheduler design (coalescing, priorities, fan-out)
- pump.md — how streamed bodies are pumped to subscribers
License
MIT — see LICENSE.