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: StringHash 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
impl Location
Sourcepub fn new(name: &str, conf: &LocationConf) -> Result<Location, Error>
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
Sourcepub fn support_grpc_web(&self) -> bool
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
Sourcepub fn validate_content_length(
&self,
header: &RequestHeader,
) -> Result<(), Error>
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
Sourcepub fn match_host_path(
&self,
host: &str,
path: &str,
) -> (bool, Option<AHashMap<String, String>>)
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
pub fn stats(&self) -> LocationStats
Trait Implementations§
Source§impl LocationInstance for Location
impl LocationInstance for Location
Source§fn on_request(&self) -> Result<(u64, i32)>
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:
- Increments the total accepted requests counter
- 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>>)
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 rewritevariables- 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 headers(&self) -> Option<&Vec<(HeaderName, HeaderValue, bool)>>
fn headers(&self) -> Option<&Vec<(HeaderName, HeaderValue, bool)>>
Source§fn client_body_size_limit(&self) -> usize
fn client_body_size_limit(&self) -> usize
Source§fn on_response(&self)
fn on_response(&self)
Auto Trait Implementations§
impl !Freeze for Location
impl RefUnwindSafe for Location
impl Send for Location
impl Sync for Location
impl Unpin for Location
impl UnsafeUnpin for Location
impl UnwindSafe for Location
Blanket Implementations§
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request