Skip to main content

Network

Trait Network 

Source
pub trait Network: Send + Sync {
    // Required methods
    fn send<'life0, 'async_trait>(
        &'life0 self,
        req: HttpRequest,
        origin: Origin,
    ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, ExecError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn permits(&self, host: &str, origin: Origin) -> bool;

    // Provided method
    fn open<'life0, 'async_trait>(
        &'life0 self,
        req: HttpRequest,
        origin: Origin,
    ) -> Pin<Box<dyn Future<Output = Result<HttpStream, ExecError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Every outbound request, in one place.

A provider follows redirects up to HttpRequest::max_redirects and must re-apply its policy to each hop: a destination the model was allowed to name could otherwise redirect to one it was not, and the allowlist would hold only for the first request of a chain. The same goes for refusing internal addresses, which also has to hold for the address it connects to, not only the one a name resolved to when it was checked.

Required Methods§

Source

fn send<'life0, 'async_trait>( &'life0 self, req: HttpRequest, origin: Origin, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, ExecError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send, and read the whole body.

Source

fn permits(&self, host: &str, origin: Origin) -> bool

Whether a host would be allowed, without sending anything.

Exists for the callers that have to decide before there is a request: Ping, and building a sandbox profile that names the hosts a subprocess may reach.

Provided Methods§

Source

fn open<'life0, 'async_trait>( &'life0 self, req: HttpRequest, origin: Origin, ) -> Pin<Box<dyn Future<Output = Result<HttpStream, ExecError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send, and hand back the body as it arrives.

The default reads it all first, which is right for a provider that answers from a fixture and wrong for one talking to a live model endpoint.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§