Skip to main content

ProxyRouter

Trait ProxyRouter 

Source
pub trait ProxyRouter:
    Send
    + Sync
    + 'static {
    // Required method
    fn route(&self, url: &Url) -> Option<Proxy>;
}
Expand description

Chooses the proxy for each request, or none to connect directly.

A router is consulted once per request, with its original URL, before connecting. A redirect or other follow-up request is routed again for its own URL; retrying protocol negotiation on the same request is not. A Proxy that a router returns still applies its own schemes and bypass entries, so a request it doesn’t carry connects directly.

Implemented for:

  • Proxy, which routes the requests its schemes and bypass entries allow;
  • functions Fn(&Url) -> Option<Proxy>;
  • Option<R>, where None routes nothing;
  • arrays and Vecs of routers, which return the first router’s proxy that isn’t None.
use trillium_client::{Proxy, Url};

let corporate = Proxy::new("http://proxy.corp.example:8080")?;
let router = move |url: &Url| {
    url.host_str()?
        .ends_with(".corp.example")
        .then(|| corporate.clone())
};

Required Methods§

Source

fn route(&self, url: &Url) -> Option<Proxy>

The proxy for a request to url, or None to connect directly.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<R: ProxyRouter, const N: usize> ProxyRouter for [R; N]

Source§

fn route(&self, url: &Url) -> Option<Proxy>

Source§

impl<R: ProxyRouter> ProxyRouter for Option<R>

Source§

fn route(&self, url: &Url) -> Option<Proxy>

Source§

impl<R: ProxyRouter> ProxyRouter for Vec<R>

Source§

fn route(&self, url: &Url) -> Option<Proxy>

Implementors§

Source§

impl ProxyRouter for Proxy

Source§

impl<F> ProxyRouter for F
where F: Fn(&Url) -> Option<Proxy> + Send + Sync + 'static,