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_proxy::Proxy;
use trillium_smol::ClientConfig;
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§async fn init(&mut self, info: &mut Info)
async fn init(&mut self, info: &mut Info)
Source§async fn run(&self, conn: Conn) -> Conn
async fn run(&self, conn: Conn) -> Conn
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::upgradeSource§async fn upgrade(&self, upgrade: Upgrade)
async fn upgrade(&self, upgrade: Upgrade)
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.