Struct Location

Source
pub struct Location {
    pub name: String,
    pub key: String,
    pub upstream: String,
    pub proxy_add_headers: Option<Vec<HttpHeader>>,
    pub proxy_set_headers: Option<Vec<HttpHeader>>,
    pub plugins: Option<Vec<String>>,
    pub enable_reverse_proxy_headers: bool,
    /* 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: String

Unique identifier for this location configuration

§key: String

Hash key used for configuration versioning and change detection

§upstream: String

Target upstream server where requests will be proxied to

§proxy_add_headers: Option<Vec<HttpHeader>>

Additional headers to append to proxied requests These are added without removing existing headers

§proxy_set_headers: Option<Vec<HttpHeader>>

Headers to set on proxied requests These override any existing headers with the same name

§plugins: Option<Vec<String>>

Ordered list of plugin names to execute during request/response processing

§enable_reverse_proxy_headers: bool

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

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 client_body_size_limit(&self, payload_size: usize) -> Result<(), Error>

Sets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client.

Source

pub fn add_processing(&self) -> Result<(u64, i32), Error>

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

pub fn sub_processing(&self)

Decrements the processing request counter for this location.

This method is called when a request finishes being processed. It performs an atomic decrement of the currently processing requests counter.

Source

pub fn match_host_path( &self, host: &str, path: &str, ) -> (bool, Option<Vec<(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 rewrite( &self, header: &mut RequestHeader, variables: Option<&AHashMap<String, String>>, ) -> bool

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

Trait Implementations§

Source§

impl Debug for Location

Source§

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

Formats the value using the given formatter. Read more

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<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
Source§

impl<T> ErasedDestructor for T
where T: 'static,