pub struct RedirectPlugin {
http_to_https: bool,
uri_tpl: Option<Template>,
ret_code: u16,
append_query_string: bool,
}Expand description
Builds a redirect response from either a uri template (with
{{namespace.path}} references plus legacy $var interpolation) or the
http_to_https shortcut.
This plugin never fails at execution time. A prepared redirect exits on
the dedicated redirect port. The only case where it does not
redirect is http_to_https on a request that is already HTTPS (per
x-forwarded-proto or the request scheme): the context passes through
unchanged on success, so http_to_https should only be wired into
routes served over plain HTTP.
Fields§
§http_to_https: boolRedirect plain-HTTP requests to https://$host$request_uri.
uri_tpl: Option<Template>Redirect target template; supports {{namespace.path}} references and
legacy $var / ${var} interpolation (see
Template::render_with_legacy).
ret_code: u16Status code for uri redirects (http_to_https picks 301/308 itself).
append_query_string: boolAppend the original query string to the target.
Implementations§
Source§impl RedirectPlugin
impl RedirectPlugin
Sourcepub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
pub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
Builds the plugin from node config.
Accepted keys — exactly one of uri / http_to_https: true is
required:
uri(string): redirect target template. Supports{{namespace.path}}references (e.g.{{request.host}}) plus legacy$var/${var}interpolation against the context (seecrate::vars::template::Template::render_with_legacy), e.g./new$request_uriorhttps://$host/login. Unknown legacy variables resolve to"".http_to_https(bool): redirect HTTP requests tohttps://$host$request_uriwith301for GET/HEAD and308otherwise (so the method and body survive). Already-HTTPS requests pass through unchanged.ret_code(integer, default302, minimum200): status code foruriredirects.append_query_string(bool, defaultfalse): append the original query string to the target (?or&as appropriate). Cannot be combined withhttp_to_https, which already keeps the query string via$request_uri.
type: redirect
config:
uri: https://$host/new-prefix$uri
ret_code: 301
append_query_string: trueTrait Implementations§
Source§impl Plugin for RedirectPlugin
impl Plugin for RedirectPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn reads_response_body(&self) -> bool
fn reads_response_body(&self) -> bool
context.response.body. Read moreSource§fn cache_target(&self) -> Option<CacheTarget>
fn cache_target(&self) -> Option<CacheTarget>
proxy-cache half. Read moreAuto Trait Implementations§
impl Freeze for RedirectPlugin
impl RefUnwindSafe for RedirectPlugin
impl Send for RedirectPlugin
impl Sync for RedirectPlugin
impl Unpin for RedirectPlugin
impl UnsafeUnpin for RedirectPlugin
impl UnwindSafe for RedirectPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more