pub trait RequestContext {
    type Method: AsRef<str>;
    type Headers;

Show 42 methods // Required methods fn request_method(&self) -> &Self::Method; fn original_uri(&self) -> &Uri; fn matched_route(&self) -> Cow<'_, str>; fn header_map(&self) -> &Self::Headers; fn get_header(&self, name: &str) -> Option<&str>; fn get_context(&self) -> Option<Context>; fn get_data<T: Clone + Send + Sync + 'static>(&self) -> Option<T>; fn set_data<T: Clone + Send + Sync + 'static>( &mut self, value: T ) -> Option<T>; fn client_ip(&self) -> Option<IpAddr>; async fn read_body_bytes(&mut self) -> Result<Bytes, Error>; // Provided methods fn request_path(&self) -> &str { ... } fn new_context(&self) -> Context { ... } fn get_trace_context(&self) -> Option<TraceContext> { ... } fn new_trace_context(&self) -> TraceContext { ... } fn new_cookie( &self, name: SharedString, value: SharedString, max_age: Option<Duration> ) -> Cookie<'static> { ... } fn get_cookie(&self, name: &str) -> Option<Cookie<'_>> { ... } fn start_time(&self) -> Instant { ... } fn instance(&self) -> String { ... } fn request_id(&self) -> Uuid { ... } fn trace_id(&self) -> Uuid { ... } fn session_id(&self) -> Option<String> { ... } fn locale(&self) -> Option<LanguageIdentifier> { ... } fn data_type(&self) -> Option<&str> { ... } fn get_param(&self, name: &str) -> Option<&str> { ... } fn parse_param<T>(&self, name: &str) -> Result<T, Rejection> where T: FromStr, <T as FromStr>::Err: Error { ... } fn get_query(&self, name: &str) -> Option<&str> { ... } fn parse_query<T: Default + DeserializeOwned>(&self) -> Result<T, Rejection> { ... } async fn parse_body<T: DeserializeOwned>(&mut self) -> Result<T, Rejection> { ... } async fn parse_multipart(&mut self) -> Result<Multipart<'_>, Rejection> { ... } async fn parse_file(&mut self) -> Result<NamedFile, Rejection> { ... } async fn parse_files(&mut self) -> Result<Vec<NamedFile>, Rejection> { ... } async fn parse_form_data<T: DeserializeOwned>( &mut self ) -> Result<(T, Vec<NamedFile>), Rejection> { ... } fn parse_authentication(&self) -> Result<Authentication, Rejection> { ... } fn parse_access_key_id(&self) -> Result<AccessKeyId, Rejection> { ... } fn parse_security_token( &self, key: &[u8] ) -> Result<SecurityToken, Rejection> { ... } fn parse_session_id(&self) -> Result<SessionId, Rejection> { ... } fn parse_jwt_claims<T, K>(&self, key: &K) -> Result<JwtClaims<T>, Rejection> where T: Default + Serialize + DeserializeOwned, K: MACLike { ... } async fn fetch( &self, resource: &str, options: Option<&Map> ) -> Result<Response, Error> { ... } async fn fetch_json<T: DeserializeOwned>( &self, resource: &str, options: Option<&Map> ) -> Result<T, Error> { ... } fn translate( &self, message: &str, args: Option<FluentArgs<'_>> ) -> Result<SharedString, Error> { ... } fn subscription(&self) -> Subscription { ... } fn cloud_event(&self, event_type: String, data: JsonValue) -> CloudEvent { ... }
}
Expand description

Request context.

Required Associated Types§

source

type Method: AsRef<str>

HTTP request method.

source

type Headers

A set of HTTP headers.

Required Methods§

source

fn request_method(&self) -> &Self::Method

Returns the request method.

source

fn original_uri(&self) -> &Uri

Returns the original request URI regardless of nesting.

source

fn matched_route(&self) -> Cow<'_, str>

Returns the route that matches the request.

source

fn header_map(&self) -> &Self::Headers

Returns a reference to the request headers.

source

fn get_header(&self, name: &str) -> Option<&str>

Gets an HTTP header value with the given name.

source

fn get_context(&self) -> Option<Context>

Gets the request context.

source

fn get_data<T: Clone + Send + Sync + 'static>(&self) -> Option<T>

Gets the request scoped data.

source

fn set_data<T: Clone + Send + Sync + 'static>(&mut self, value: T) -> Option<T>

Sets the request scoped data and returns the old value if an item of this type was already stored.

source

fn client_ip(&self) -> Option<IpAddr>

Returns the client’s remote IP.

source

async fn read_body_bytes(&mut self) -> Result<Bytes, Error>

Reads the entire request body into a byte buffer.

Provided Methods§

source

fn request_path(&self) -> &str

Returns the request path regardless of nesting.

source

fn new_context(&self) -> Context

Creates a new request context.

source

fn get_trace_context(&self) -> Option<TraceContext>

Returns the trace context by parsing the traceparent and tracestate header values.

source

fn new_trace_context(&self) -> TraceContext

Creates a new TraceContext.

Creates a new cookie with the given name and value.

Gets a cookie with the given name.

source

fn start_time(&self) -> Instant

Returns the start time.

source

fn instance(&self) -> String

Returns the instance.

source

fn request_id(&self) -> Uuid

Returns the request ID.

source

fn trace_id(&self) -> Uuid

Returns the trace ID.

source

fn session_id(&self) -> Option<String>

Returns the session ID.

source

fn locale(&self) -> Option<LanguageIdentifier>

Returns the locale.

source

fn data_type(&self) -> Option<&str>

Gets the data type by parsing the content-type header.

source

fn get_param(&self, name: &str) -> Option<&str>

Gets the route parameter by name. The name should not include :, *, { or }.

Note

Please note that it does not handle the percent-decoding. You can use parse_param() if you need percent-decoding.

source

fn parse_param<T>(&self, name: &str) -> Result<T, Rejection>
where T: FromStr, <T as FromStr>::Err: Error,

Parses the route parameter by name as an instance of type T. The name should not include :, *, { or }.

source

fn get_query(&self, name: &str) -> Option<&str>

Gets the query value of the URI by name.

Note

Please note that it does not handle the percent-decoding. You can use parse_query() if you need percent-decoding.

source

fn parse_query<T: Default + DeserializeOwned>(&self) -> Result<T, Rejection>

Parses the query as an instance of type T. Returns a default value of T when the query is empty. If the query has a timestamp parameter, it will be used to prevent replay attacks.

source

async fn parse_body<T: DeserializeOwned>(&mut self) -> Result<T, Rejection>

Parses the request body as an instance of type T.

Note

Currently, we have built-in support for the following content-type header values:

  • application/json
  • application/msgpack
  • application/problem+json
  • application/x-www-form-urlencoded
source

async fn parse_multipart(&mut self) -> Result<Multipart<'_>, Rejection>

Parses the request body as a multipart, which is commonly used with file uploads.

source

async fn parse_file(&mut self) -> Result<NamedFile, Rejection>

Parses the request body as a file.

source

async fn parse_files(&mut self) -> Result<Vec<NamedFile>, Rejection>

Parses the request body as a list of files.

source

async fn parse_form_data<T: DeserializeOwned>( &mut self ) -> Result<(T, Vec<NamedFile>), Rejection>

Parses the multipart/form-data as an instance of type T and a list of files.

source

fn parse_authentication(&self) -> Result<Authentication, Rejection>

Attempts to construct an instance of Authentication from an HTTP request. The value is extracted from the query or the authorization header. By default, the Accept header value is ignored and the canonicalized resource is set to the request path. You should always manually set canonicalized headers by calling Authentication’s method set_headers().

source

fn parse_access_key_id(&self) -> Result<AccessKeyId, Rejection>

Attempts to construct an instance of AccessKeyId from an HTTP request. The value is extracted from the query parameter access_key_id or the authorization header.

source

fn parse_security_token(&self, key: &[u8]) -> Result<SecurityToken, Rejection>

Attempts to construct an instance of SecurityToken from an HTTP request. The value is extracted from the x-security-token header.

source

fn parse_session_id(&self) -> Result<SessionId, Rejection>

Attempts to construct an instance of SessionId from an HTTP request. The value is extracted from the x-session-id or session-id header.

source

fn parse_jwt_claims<T, K>(&self, key: &K) -> Result<JwtClaims<T>, Rejection>

Attempts to construct an instance of JwtClaims from an HTTP request. The value is extracted from the query parameter access_token or the authorization header.

source

async fn fetch( &self, resource: &str, options: Option<&Map> ) -> Result<Response, Error>

Makes an HTTP request to the provided resource using reqwest.

source

async fn fetch_json<T: DeserializeOwned>( &self, resource: &str, options: Option<&Map> ) -> Result<T, Error>

Makes an HTTP request to the provided resource and deserializes the response body via JSON.

source

fn translate( &self, message: &str, args: Option<FluentArgs<'_>> ) -> Result<SharedString, Error>

Translates the localization message.

source

fn subscription(&self) -> Subscription

Constructs a new subscription instance.

source

fn cloud_event(&self, event_type: String, data: JsonValue) -> CloudEvent

Constructs a new cloud event instance.

Object Safety§

This trait is not object safe.

Implementors§