Skip to main content

ServiceRequest

Struct ServiceRequest 

Source
pub struct ServiceRequest(/* private fields */);
Expand description

An service http request

ServiceRequest allows mutable access to request’s internal structures

Implementations§

Source§

impl ServiceRequest

Source

pub fn into_parts(self) -> (HttpRequest, Payload)

Deconstruct request into parts

Source

pub fn from_parts( req: HttpRequest, pl: Payload, ) -> Result<Self, (HttpRequest, Payload)>

Construct request from parts.

ServiceRequest can be re-constructed only if req hasnt been cloned.

Source

pub fn from_request(req: HttpRequest) -> Result<Self, HttpRequest>

Construct request from request.

HttpRequest implements Clone trait via Rc type. ServiceRequest can be re-constructed only if rc’s strong pointers count eq 1 and weak pointers count is 0.

Source

pub fn into_response<B, R: Into<Response<B>>>( self, res: R, ) -> ServiceResponse<B>

Create service response

Source

pub fn error_response<B, E: Into<Error>>(self, err: E) -> ServiceResponse<B>

Create service response for error

Source

pub fn head(&self) -> &RequestHead

This method returns reference to the request head

Source

pub fn head_mut(&mut self) -> &mut RequestHead

This method returns reference to the request head

Source

pub fn uri(&self) -> &Uri

Request’s uri.

Source

pub fn method(&self) -> &Method

Read the Request method.

Source

pub fn version(&self) -> Version

Read the Request Version.

Source

pub fn headers(&self) -> &HeaderMap

Returns request’s headers.

Source

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

Returns mutable request’s headers.

Source

pub fn path(&self) -> &str

The target path of this Request.

Source

pub fn query_string(&self) -> &str

The query string in the URL.

E.g., id=10

Source

pub fn peer_addr(&self) -> Option<SocketAddr>

Peer socket address

Peer address is actual socket address, if proxy is used in front of Eternal http server, then peer address would be address of this proxy.

To get client connection information ConnectionInfo should be used.

Source

pub fn connection_info(&self) -> Ref<'_, ConnectionInfo>

Get ConnectionInfo for the current request.

Source

pub fn match_info(&self) -> &Path<Url>

Get a reference to the Path parameters.

Params is a container for url parameters. A variable segment is specified in the form {identifier}, where the identifier can be used later in a request handler to access the matched value for that segment.

Source

pub fn match_info_mut(&mut self) -> &mut Path<Url>

Get a mutable reference to the Path parameters.

Source

pub fn resource_map(&self) -> &ResourceMap

Get a reference to a ResourceMap of current application.

Source

pub fn app_config(&self) -> &AppConfig

Service configuration

Source

pub fn app_data<T: 'static>(&self) -> Option<Data<T>>

Get an application data stored with App::data() method during application configuration.

Source

pub fn set_payload(&mut self, payload: Payload)

Set request payload.

Trait Implementations§

Source§

impl Debug for ServiceRequest

Source§

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

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

impl HttpMessage for ServiceRequest

Source§

fn headers(&self) -> &HeaderMap

Returns Request’s headers.

Source§

fn extensions(&self) -> Ref<'_, Extensions>

Request extensions

Source§

fn extensions_mut(&self) -> RefMut<'_, Extensions>

Mutable reference to a the request’s extensions

Source§

type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>>>>

Type of message payload stream
Source§

fn take_payload(&mut self) -> Payload<Self::Stream>

Message payload stream
Source§

fn content_type(&self) -> &str

Read the request content type. If request does not contain Content-Type header, empty str get returned.
Source§

fn encoding(&self) -> Result<&'static Encoding, ContentTypeError>

Get content type encoding Read more
Source§

fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>

Convert the request content type to a known mime type.
Source§

fn chunked(&self) -> Result<bool, ParseError>

Check if request has chunked transfer encoding
Source§

fn cookies(&self) -> Result<Ref<'_, Vec<Cookie<'static>>>, CookieParseError>

Load request cookies.
Source§

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

Return request cookie.
Source§

impl Resource<Url> for ServiceRequest

Source§

fn resource_path(&mut self) -> &mut Path<Url>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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