Struct trillium_proxy::Proxy
source · pub struct Proxy<U> { /* private fields */ }
Expand description
the proxy handler
Implementations§
source§impl<U: UpstreamSelector> Proxy<U>
impl<U: UpstreamSelector> Proxy<U>
sourcepub fn new<I>(client: impl Into<Client>, upstream: I) -> Selfwhere
I: IntoUpstreamSelector<UpstreamSelector = U>,
pub fn new<I>(client: impl Into<Client>, upstream: I) -> Selfwhere
I: IntoUpstreamSelector<UpstreamSelector = U>,
construct a new proxy handler that sends all requests to the upstream provided
use trillium_smol::ClientConfig;
use trillium_proxy::Proxy;
let proxy = Proxy::new(ClientConfig::default(), "http://docs.trillium.rs/trillium_proxy");
sourcepub fn proxy_not_found(self) -> Self
pub fn proxy_not_found(self) -> Self
chainable constructor to set the 404 Not Found handling
behavior. By default, this proxy will pass through the trillium
Conn unmodified if the proxy response is a 404 not found, allowing
it to be chained in a tuple handler. To modify this behavior, call
proxy_not_found, and the full 404 response will be forwarded. The
Conn will be halted unless Proxy::without_halting
was
configured
let proxy = Proxy::new(ClientConfig::default(), "http://trillium.rs")
.proxy_not_found();
sourcepub fn without_halting(self) -> Self
pub fn without_halting(self) -> Self
The default behavior for this handler is to halt the conn on any
response other than a 404. If Proxy::proxy_not_found
has been
configured, the default behavior for all response statuses is to
halt the trillium conn. To change this behavior, call
without_halting when constructing the proxy, and it will not halt
the conn. This is useful when passing the proxy reply through
trillium_html_rewriter
.
let proxy = Proxy::new(ClientConfig::default(), "http://trillium.rs")
.without_halting();
sourcepub fn with_via_pseudonym(
self,
via_pseudonym: impl Into<Cow<'static, str>>,
) -> Self
pub fn with_via_pseudonym( self, via_pseudonym: impl Into<Cow<'static, str>>, ) -> Self
populate the pseudonym for a
Via
header. If no pseudonym is provided, no via header will be
inserted.
sourcepub fn with_websocket_upgrades(self) -> Self
pub fn with_websocket_upgrades(self) -> Self
Allow websockets to be proxied
This is not currently the default, but that may change at some (semver-minor) point in the future
Trait Implementations§
source§impl<U: UpstreamSelector> Handler for Proxy<U>
impl<U: UpstreamSelector> Handler for Proxy<U>
source§fn init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_info: &'life1 mut Info,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn init<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_info: &'life1 mut Info,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
source§fn run<'life0, 'async_trait>(
&'life0 self,
conn: Conn,
) -> Pin<Box<dyn Future<Output = Conn> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
conn: Conn,
) -> Pin<Box<dyn Future<Output = Conn> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
source§fn has_upgrade(&self, upgrade: &Upgrade) -> bool
fn has_upgrade(&self, upgrade: &Upgrade) -> bool
Handler::upgrade
. The first
handler that responds true to this will receive ownership of the
trillium::Upgrade
in a subsequent call to Handler::upgrade
source§fn upgrade<'life0, 'async_trait>(
&'life0 self,
upgrade: Upgrade,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn upgrade<'life0, 'async_trait>(
&'life0 self,
upgrade: Upgrade,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handler::has_upgrade
and will only be called once for this
upgrade. There is no return value, and this function takes
exclusive ownership of the underlying transport once this is
called. You can downcast the transport to whatever the source
transport type is and perform any non-http protocol communication
that has been negotiated. You probably don’t want this unless
you’re implementing something like websockets. Please note that
for many transports such as TcpStreams, dropping the transport
(and therefore the Upgrade) will hang up / disconnect.