pub struct Http { /* private fields */ }Expand description
Loader for the http source: fetches configuration bytes through a user-supplied closure.
This crate ships no HTTP client — you provide the transport as an HttpFetchFn when calling
Http::new. The loader validates options, calls your closure with the resolved URL,
headers, timeout, and TLS policy, then normalizes the returned entries (see the
module docs).
§Example
use std::collections::HashMap;
use std::time::Duration;
use tanzim_load::{http::{Http, Url}, Load, Payload};
use tanzim_source::SourceBuilder;
// A real fetch would call an HTTP client here; this canned closure needs no network.
let http = Http::new(Box::new(
|url: &Url, _headers: &HashMap<String, String>, _timeout: Duration, _insecure: bool| {
Ok(vec![Payload {
source: SourceBuilder::new()
.with_source("http")
.with_resource(url.as_str())
.build()
.unwrap(),
maybe_name: Some("app".into()),
maybe_format: Some("json".into()),
content: br#"{"debug":true}"#.to_vec(),
}])
},
));
let source = SourceBuilder::new()
.with_source("http")
.with_resource("https://example.com/config.json")
.build()
.unwrap();
let payloads = http.load(source).unwrap();
assert_eq!(payloads[0].maybe_name.as_deref(), Some("app"));Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Http
impl !UnwindSafe for Http
impl Freeze for Http
impl Send for Http
impl Sync for Http
impl Unpin for Http
impl UnsafeUnpin for Http
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more