Skip to main content

Location

Struct Location 

Source
pub struct Location {
    pub name: Arc<str>,
    pub key: String,
    pub headers: Option<Vec<(HeaderName, HeaderValue, bool)>>,
    pub plugins: Option<Vec<String>>,
    pub max_retries: Option<u8>,
    pub max_retry_window: Option<Duration>,
    /* private fields */
}
Expand description

Location represents a routing configuration for handling HTTP requests. It defines rules for matching requests based on paths and hosts, and specifies how these requests should be processed and proxied.

Fields§

§name: Arc<str>

Unique identifier for this location configuration

§key: String

Hash key used for configuration versioning and change detection

§headers: Option<Vec<(HeaderName, HeaderValue, bool)>>

Headers to set or append on proxied requests

§plugins: Option<Vec<String>>

Additional headers to append to proxied requests These are added without removing existing headers Headers to set on proxied requests These override any existing headers with the same name Ordered list of plugin names to execute during request/response processing

§max_retries: Option<u8>

Whether to automatically add standard reverse proxy headers like: X-Forwarded-For, X-Real-IP, X-Forwarded-Proto, etc. Maximum window for retries

§max_retry_window: Option<Duration>

Maximum window for retries

Implementations§

Source§

impl Location

Source

pub fn new(name: &str, conf: &LocationConf) -> Result<Location, Error>

Creates a new Location from configuration Validates and compiles path/host patterns and other settings

Source

pub fn support_grpc_web(&self) -> bool

Returns whether gRPC-Web protocol support is enabled for this location When enabled, the proxy will handle gRPC-Web requests and convert them to regular gRPC

Source

pub fn validate_content_length( &self, header: &RequestHeader, ) -> Result<(), Error>

Validates that the request’s Content-Length header does not exceed the configured maximum

§Arguments
  • header - The HTTP request header to validate
§Returns
  • Result<()> - Ok if validation passes, Error::BodyTooLarge if content length exceeds limit
§Notes
  • Returns Ok if client_max_body_size is 0 (unlimited)
  • Uses get_content_length() helper to parse the Content-Length header
Source

pub fn match_host_path( &self, host: &str, path: &str, ) -> (bool, Option<AHashMap<String, String>>)

Checks if a request matches this location’s path and host rules Returns a tuple containing:

  • bool: Whether the request matched both path and host rules
  • Option<Vec<(String, String)>>: Any captured variables from regex host matching
Source

pub fn stats(&self) -> LocationStats

Trait Implementations§

Source§

impl Debug for Location

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LocationInstance for Location

Source§

fn on_request(&self) -> Result<(u64, i32)>

Increments the processing and accepted request counters for this location.

This method is called when a new request starts being processed by this location. It performs two atomic operations:

  1. Increments the total accepted requests counter
  2. Increments the currently processing requests counter
§Returns
  • Result<(u64, i32)> - A tuple containing:
    • The new total number of accepted requests (u64)
    • The new number of currently processing requests (i32)
§Errors

Returns Error::TooManyRequest if the number of currently processing requests would exceed the configured max_processing limit (when non-zero).

Source§

fn rewrite( &self, header: &mut RequestHeader, variables: Option<AHashMap<String, String>>, ) -> (bool, Option<AHashMap<String, String>>)

Applies URL rewriting rules if configured for this location.

This method performs path rewriting based on regex patterns and replacement rules. It supports variable interpolation from captured values in the host matching.

§Arguments
  • header - Mutable reference to the request header containing the URI to rewrite
  • variables - Optional map of variables captured from host matching that can be interpolated into the replacement value
§Returns
  • bool - Returns true if the path was rewritten, false if no rewriting was performed
§Examples
// Configuration example:
// rewrite: "^/users/(.*)$ /api/users/$1"
// This would rewrite "/users/123" to "/api/users/123"
§Notes
  • Preserves query parameters when rewriting the path
  • Logs debug information about path rewrites
  • Logs errors if the new path cannot be parsed as a valid URI
Source§

fn name(&self) -> &str

Get location’s name
Source§

fn headers(&self) -> Option<&Vec<(HeaderName, HeaderValue, bool)>>

Returns the proxy header to upstream
Source§

fn client_body_size_limit(&self) -> usize

Returns the client body size limit
Source§

fn upstream(&self) -> &str

Get the upstream of location
Source§

fn on_response(&self)

Called when the response is received from the upstream

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more