Struct salvo_core::http::request::Request

source ·
pub struct Request { /* private fields */ }
Expand description

Represents an HTTP request.

Stores all the properties of the client’s request.

Implementations§

source§

impl Request

source

pub fn new() -> Request

Creates a new blank Request

source

pub fn from_hyper<B>(req: Request<B>, scheme: Scheme) -> Self
where B: Into<ReqBody>,

Creates a new Request from hyper::Request.

source

pub fn uri(&self) -> &Uri

Returns a reference to the associated URI.

§Examples
let req = Request::default();
assert_eq!(*req.uri(), *"/");
source

pub fn uri_mut(&mut self) -> &mut Uri

Returns a mutable reference to the associated URI.

Notice: If you using this mutable reference to change the uri, you should change the params and queries manually.

§Examples
let mut req: Request= Request::default();
*req.uri_mut() = "/hello".parse().unwrap();
assert_eq!(*req.uri(), *"/hello");
source

pub fn set_uri(&mut self, uri: Uri)

Set the associated URI. querie will be reset.

Notice: params will not reset.

source

pub fn method(&self) -> &Method

Returns a reference to the associated HTTP method.

§Examples
let req = Request::default();
assert_eq!(*req.method(), Method::GET);
source

pub fn method_mut(&mut self) -> &mut Method

Returns a mutable reference to the associated HTTP method.

§Examples
let mut request: Request = Request::default();
*request.method_mut() = Method::PUT;
assert_eq!(*request.method(), Method::PUT);
source

pub fn version(&self) -> Version

Returns the associated version.

source

pub fn version_mut(&mut self) -> &mut Version

Returns a mutable reference to the associated version.

source

pub fn scheme(&self) -> &Scheme

Returns the associated scheme.

source

pub fn scheme_mut(&mut self) -> &mut Scheme

Returns a mutable reference to the associated scheme.

source

pub fn remote_addr(&self) -> &SocketAddr

Get request remote address.

source

pub fn remote_addr_mut(&mut self) -> &mut SocketAddr

Get request remote address.

source

pub fn local_addr(&self) -> &SocketAddr

Get request remote address reference.

source

pub fn local_addr_mut(&mut self) -> &mut SocketAddr

Get mutable request remote address reference.

source

pub fn headers(&self) -> &HeaderMap

Returns a reference to the associated header field map.

§Examples
let req = Request::default();
assert!(req.headers().is_empty());
source

pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>

Returns a mutable reference to the associated header field map.

§Examples
let mut req: Request = Request::default();
req.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!req.headers().is_empty());
source

pub fn header<'de, T>(&'de self, key: impl AsHeaderName) -> Option<T>
where T: Deserialize<'de>,

Get header with supplied name and try to parse to a ‘T’, returns None if failed or not found.

source

pub fn add_header<N, V>( &mut self, name: N, value: V, overwrite: bool ) -> Result<&mut Self>

Modify a header for this request.

When overwrite is set to true, If the header is already present, the value will be replaced. When overwrite is set to false, The new header is always appended to the request, even if the header already exists.

source

pub fn body(&self) -> &ReqBody

Returns a reference to the associated HTTP body.

source

pub fn body_mut(&mut self) -> &mut ReqBody

Returns a mutable reference to the associated HTTP body.

source

pub fn replace_body(&mut self, body: ReqBody) -> ReqBody

Sets body to a new value and returns old value.

source

pub fn take_body(&mut self) -> ReqBody

Take body form the request, and set the body to None in the request.

source

pub fn extensions(&self) -> &Extensions

Returns a reference to the associated extensions.

§Examples
let req = Request::default();
assert!(req.extensions().get::<i32>().is_none());
source

pub async fn web_transport_mut( &mut self ) -> Result<&mut WebTransportSession<Connection, Bytes>, Error>

Available on crate feature quinn only.

Try to get a WebTransport session from the request.

source

pub fn extensions_mut(&mut self) -> &mut Extensions

Returns a mutable reference to the associated extensions.

§Examples
let mut req = Request::default();
req.extensions_mut().insert("hello");
assert_eq!(req.extensions().get(), Some(&"hello"));
source

pub fn accept(&self) -> Vec<Mime>

Get accept.

source

pub fn first_accept(&self) -> Option<Mime>

Get first accept.

source

pub fn content_type(&self) -> Option<Mime>

Get content type.

source

pub fn cookies(&self) -> &CookieJar

Available on crate feature cookie only.

Get CookieJar reference.

source

pub fn cookies_mut(&mut self) -> &mut CookieJar

Available on crate feature cookie only.

Get CookieJar mutable reference.

source

pub fn cookie<T>(&self, name: T) -> Option<&Cookie<'static>>
where T: AsRef<str>,

Available on crate feature cookie only.

Get Cookie from cookies.

source

pub fn params(&self) -> &IndexMap<String, String>

Get params reference.

source

pub fn params_mut(&mut self) -> &mut IndexMap<String, String>

Get params mutable reference.

source

pub fn param<'de, T>(&'de self, key: &str) -> Option<T>
where T: Deserialize<'de>,

Get param value from params.

source

pub fn queries(&self) -> &MultiMap<String, String>

Get queries reference.

source

pub fn queries_mut(&mut self) -> &mut MultiMap<String, String>

Get mutable queries reference.

source

pub fn query<'de, T>(&'de self, key: &str) -> Option<T>
where T: Deserialize<'de>,

Get query value from queries.

source

pub async fn form<'de, T>(&'de mut self, key: &str) -> Option<T>
where T: Deserialize<'de>,

Get field data from form.

source

pub async fn form_or_query<'de, T>(&'de mut self, key: &str) -> Option<T>
where T: Deserialize<'de>,

Get field data from form, if key is not found in form data, then get from query.

source

pub async fn query_or_form<'de, T>(&'de mut self, key: &str) -> Option<T>
where T: Deserialize<'de>,

Get value from query, if key is not found in queries, then get from form.

source

pub async fn file<'a>(&'a mut self, key: &'a str) -> Option<&'a FilePart>

Get FilePart reference from request.

source

pub async fn first_file(&mut self) -> Option<&FilePart>

Get FilePart reference from request.

source

pub async fn files<'a>(&'a mut self, key: &'a str) -> Option<&'a Vec<FilePart>>

Get FilePart list reference from request.

source

pub async fn all_files(&mut self) -> Vec<&FilePart>

Get FilePart list reference from request.

source

pub async fn payload(&mut self) -> Result<&Bytes, ParseError>

Get request payload with default max size limit(64KB).

https://github.com/hyperium/hyper/issues/3111 *Notice: This method takes body.

source

pub async fn payload_with_max_size( &mut self, max_size: usize ) -> Result<&Bytes, ParseError>

Get request payload with max size limit.

https://github.com/hyperium/hyper/issues/3111 *Notice: This method takes body.

source

pub async fn form_data(&mut self) -> Result<&FormData, ParseError>

Get FormData reference from request.

*Notice: This method takes body and body’s size is not limited.

source

pub async fn extract<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Extractible<'de> + Deserialize<'de> + Send,

Extract request as type T from request’s different parts.

source

pub async fn extract_with_metadata<'de, T>( &'de mut self, metadata: &'de Metadata ) -> Result<T, ParseError>
where T: Deserialize<'de> + Send,

Extract request as type T from request’s different parts.

source

pub fn parse_params<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse url params as type T from request.

source

pub fn parse_queries<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse queries as type T from request.

source

pub fn parse_headers<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse headers as type T from request.

source

pub fn parse_cookies<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Deserialize<'de>,

Available on crate feature cookie only.

Parse cookies as type T from request.

source

pub async fn parse_json<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse json body as type T from request with default max size limit.

source

pub async fn parse_json_with_max_size<'de, T>( &'de mut self, max_size: usize ) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse json body as type T from request with max size limit.

source

pub async fn parse_form<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse form body as type T from request.

source

pub async fn parse_body<'de, T>(&'de mut self) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse json body or form body as type T from request with default max size.

source

pub async fn parse_body_with_max_size<'de, T>( &'de mut self, max_size: usize ) -> Result<T, ParseError>
where T: Deserialize<'de>,

Parse json body or form body as type T from request with max size.

Trait Implementations§

source§

impl Debug for Request

source§

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

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

impl Default for Request

source§

fn default() -> Request

Returns the “default value” for a type. 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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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