pub struct HttpClient { /* private fields */ }Expand description
HTTP client shared by HTTP-calling nodes. Register it in
graphrt_core::Services; when absent, nodes use a client with the default
(restrictive) EgressPolicy.
Every connection goes through the policy:
- literal-IP URLs and every redirect hop are validated before connecting;
- host names are resolved by a guarded resolver that refuses non-public addresses, and the connection is made to exactly the addresses it returned (so DNS rebinding cannot swap in a private address afterwards);
- environment proxy variables are ignored.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(policy: EgressPolicy) -> Result<Self, ClientError>
pub fn new(policy: EgressPolicy) -> Result<Self, ClientError>
Build a client enforcing policy. The proxy setting is validated here;
the underlying connections are set up on first use.
@throws ClientError::Proxy when policy.proxy is not a valid proxy URL.
Sourcepub fn trusted() -> Result<Self, ClientError>
pub fn trusted() -> Result<Self, ClientError>
Client with EgressPolicy::trusted, for operator-configured endpoints.
pub fn policy(&self) -> &EgressPolicy
Sourcepub fn client(&self, verify_tls: bool) -> Result<&Client, ClientError>
pub fn client(&self, verify_tls: bool) -> Result<&Client, ClientError>
Underlying client, built on first use. verify_tls = false disables
certificate verification.
Redirects are followed automatically (each hop re-validated). reqwest strips only
authorization, cookie and proxy-authorization on cross-host hops, so callers
sending other credential headers should use HttpClient::manual_redirect_client.
@throws ClientError::Build when the TLS backend cannot be initialised.
Sourcepub fn manual_redirect_client(
&self,
verify_tls: bool,
) -> Result<&Client, ClientError>
pub fn manual_redirect_client( &self, verify_tls: bool, ) -> Result<&Client, ClientError>
Client that never follows redirects: 3xx responses are returned to the caller.
@throws ClientError::Build when the TLS backend cannot be initialised.