Trait edm_core::request::RequestContext
source · 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§
Required Methods§
sourcefn request_method(&self) -> &Self::Method
fn request_method(&self) -> &Self::Method
Returns the request method.
sourcefn original_uri(&self) -> &Uri
fn original_uri(&self) -> &Uri
Returns the original request URI regardless of nesting.
sourcefn matched_route(&self) -> Cow<'_, str>
fn matched_route(&self) -> Cow<'_, str>
Returns the route that matches the request.
sourcefn header_map(&self) -> &Self::Headers
fn header_map(&self) -> &Self::Headers
Returns a reference to the request headers.
sourcefn get_header(&self, name: &str) -> Option<&str>
fn get_header(&self, name: &str) -> Option<&str>
Gets an HTTP header value with the given name.
sourcefn get_context(&self) -> Option<Context>
fn get_context(&self) -> Option<Context>
Gets the request context.
sourcefn get_data<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
fn get_data<T: Clone + Send + Sync + 'static>(&self) -> Option<T>
Gets the request scoped data.
sourcefn set_data<T: Clone + Send + Sync + 'static>(&mut self, value: T) -> Option<T>
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.
sourceasync fn read_body_bytes(&mut self) -> Result<Bytes, Error>
async fn read_body_bytes(&mut self) -> Result<Bytes, Error>
Reads the entire request body into a byte buffer.
Provided Methods§
sourcefn request_path(&self) -> &str
fn request_path(&self) -> &str
Returns the request path regardless of nesting.
sourcefn new_context(&self) -> Context
fn new_context(&self) -> Context
Creates a new request context.
sourcefn get_trace_context(&self) -> Option<TraceContext>
fn get_trace_context(&self) -> Option<TraceContext>
Returns the trace context by parsing the traceparent and tracestate header values.
sourcefn new_trace_context(&self) -> TraceContext
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.
sourcefn start_time(&self) -> Instant
fn start_time(&self) -> Instant
Returns the start time.
sourcefn request_id(&self) -> Uuid
fn request_id(&self) -> Uuid
Returns the request ID.
sourcefn session_id(&self) -> Option<String>
fn session_id(&self) -> Option<String>
Returns the session ID.
sourcefn get_param(&self, name: &str) -> Option<&str>
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.
sourcefn parse_param<T>(&self, name: &str) -> Result<T, Rejection>
fn parse_param<T>(&self, name: &str) -> Result<T, Rejection>
Parses the route parameter by name as an instance of type T.
The name should not include :, *, { or }.
sourcefn get_query(&self, name: &str) -> Option<&str>
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.
sourcefn parse_query<T: Default + DeserializeOwned>(&self) -> Result<T, Rejection>
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.
sourceasync fn parse_body<T: DeserializeOwned>(&mut self) -> Result<T, Rejection>
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/jsonapplication/msgpackapplication/problem+jsonapplication/x-www-form-urlencoded
sourceasync fn parse_multipart(&mut self) -> Result<Multipart<'_>, Rejection>
async fn parse_multipart(&mut self) -> Result<Multipart<'_>, Rejection>
Parses the request body as a multipart, which is commonly used with file uploads.
sourceasync fn parse_file(&mut self) -> Result<NamedFile, Rejection>
async fn parse_file(&mut self) -> Result<NamedFile, Rejection>
Parses the request body as a file.
sourceasync fn parse_files(&mut self) -> Result<Vec<NamedFile>, Rejection>
async fn parse_files(&mut self) -> Result<Vec<NamedFile>, Rejection>
Parses the request body as a list of files.
sourceasync fn parse_form_data<T: DeserializeOwned>(
&mut self
) -> Result<(T, Vec<NamedFile>), Rejection>
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.
sourcefn parse_authentication(&self) -> Result<Authentication, Rejection>
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().
sourcefn parse_access_key_id(&self) -> Result<AccessKeyId, Rejection>
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.
sourcefn parse_security_token(&self, key: &[u8]) -> Result<SecurityToken, Rejection>
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.
sourcefn parse_session_id(&self) -> Result<SessionId, Rejection>
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.
sourcefn parse_jwt_claims<T, K>(&self, key: &K) -> Result<JwtClaims<T>, Rejection>
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.
sourceasync fn fetch(
&self,
resource: &str,
options: Option<&Map>
) -> Result<Response, Error>
async fn fetch( &self, resource: &str, options: Option<&Map> ) -> Result<Response, Error>
Makes an HTTP request to the provided resource
using reqwest.
sourceasync fn fetch_json<T: DeserializeOwned>(
&self,
resource: &str,
options: Option<&Map>
) -> Result<T, Error>
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.
sourcefn translate(
&self,
message: &str,
args: Option<FluentArgs<'_>>
) -> Result<SharedString, Error>
fn translate( &self, message: &str, args: Option<FluentArgs<'_>> ) -> Result<SharedString, Error>
Translates the localization message.
sourcefn subscription(&self) -> Subscription
fn subscription(&self) -> Subscription
Constructs a new subscription instance.
sourcefn cloud_event(&self, event_type: String, data: JsonValue) -> CloudEvent
fn cloud_event(&self, event_type: String, data: JsonValue) -> CloudEvent
Constructs a new cloud event instance.