pub struct WebRequest<St = ()> { /* private fields */ }Expand description
An service http request
WebRequest allows mutable access to request’s internal structures
Implementations§
Source§impl<St> WebRequest<St>
impl<St> WebRequest<St>
Sourcepub fn error_response<AppSt, E>(self, st: &AppSt, err: &E) -> WebResponse
pub fn error_response<AppSt, E>(self, st: &AppSt, err: &E) -> WebResponse
Create web response for error
Source§impl WebRequest<()>
impl WebRequest<()>
Sourcepub fn from_request(req: HttpRequest) -> Self
pub fn from_request(req: HttpRequest) -> Self
Construct request from request.
Source§impl<St> WebRequest<St>
impl<St> WebRequest<St>
Sourcepub fn into_parts(self) -> (HttpRequest, Payload, St)
pub fn into_parts(self) -> (HttpRequest, Payload, St)
Deconstruct request into parts
Sourcepub fn from_parts(req: HttpRequest, payload: Payload, state: St) -> Self
pub fn from_parts(req: HttpRequest, payload: Payload, state: St) -> Self
Construct request from parts.
Sourcepub fn into_response<R: Into<Response>>(self, res: R) -> WebResponse
pub fn into_response<R: Into<Response>>(self, res: R) -> WebResponse
Create web response
Sourcepub fn head(&self) -> &RequestHead
pub fn head(&self) -> &RequestHead
This method returns reference to the request head
Sourcepub fn head_mut(&mut self) -> &mut RequestHead
pub fn head_mut(&mut self) -> &mut RequestHead
This method returns mutable reference to the request head
Sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Returns mutable request’s headers.
Sourcepub fn query_string(&self) -> &str
pub fn query_string(&self) -> &str
The query string in the URL.
E.g., id=10
Sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Peer socket address
Peer address is actual socket address, if proxy is used in front of ntex http server, then peer address would be address of this proxy.
To get client connection information ConnectionInfo should be used.
Sourcepub fn take_payload(&mut self) -> Payload
pub fn take_payload(&mut self) -> Payload
Take request’s payload.
The payload is replaced with an empty one, so subsequent calls return an empty payload.
Sourcepub fn set_payload(&mut self, payload: Payload)
pub fn set_payload(&mut self, payload: Payload)
Set request payload.
Sourcepub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
Get ConnectionInfo for the current request.
Sourcepub fn match_info(&self) -> &Path<Url>
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.
Sourcepub fn match_info_mut(&mut self) -> &mut Path<Url>
pub fn match_info_mut(&mut self) -> &mut Path<Url>
Get a mutable reference to the Path parameters.
Sourcepub fn resource_map(&self) -> &ResourceMap
pub fn resource_map(&self) -> &ResourceMap
Get a reference to a ResourceMap of current application.
Sourcepub fn app_config(&self) -> &WebAppConfig
pub fn app_config(&self) -> &WebAppConfig
Service configuration
Sourcepub fn extensions(&self) -> Ref<'_, Extensions>
pub fn extensions(&self) -> Ref<'_, Extensions>
Request extensions
Sourcepub fn extensions_mut(&self) -> RefMut<'_, Extensions>
pub fn extensions_mut(&self) -> RefMut<'_, Extensions>
Mutable reference to a the request’s extensions
Sourcepub fn map_state<F, NewSt>(self, f: F) -> WebRequest<NewSt>where
F: FnOnce(St) -> NewSt,
pub fn map_state<F, NewSt>(self, f: F) -> WebRequest<NewSt>where
F: FnOnce(St) -> NewSt,
Transform the request state into a new type.
This method consumes the request and returns request with different
state a WebRequest<NewSt>. The HTTP request and payload are preserved.
It is useful in application and resource filters that add
request-specific data before passing the request to the next service.
Application state is not affected; only the state stored in this
WebRequest is replaced.
use std::convert::Infallible;
use ntex::web::{self, WebRequest};
async fn index(_: &(), user_id: usize) -> String {
format!("User {user_id}")
}
web::App::default()
.filter(async |req: WebRequest<()>| {
Ok::<_, Infallible>(req.map_state(|()| 42usize))
})
.service(web::resource("/").to_with_state(index));Trait Implementations§
Source§impl<St> Debug for WebRequest<St>
impl<St> Debug for WebRequest<St>
Source§impl<St> HttpMessage for WebRequest<St>
impl<St> HttpMessage for WebRequest<St>
Source§fn message_headers(&self) -> &HeaderMap
fn message_headers(&self) -> &HeaderMap
Returns Request’s headers.
Source§fn message_extensions(&self) -> Ref<'_, Extensions>
fn message_extensions(&self) -> Ref<'_, Extensions>
Request extensions
Source§fn message_extensions_mut(&self) -> RefMut<'_, Extensions>
fn message_extensions_mut(&self) -> RefMut<'_, Extensions>
Mutable reference to a the request’s extensions
Source§fn content_type(&self) -> &str
fn content_type(&self) -> &str
Content-Type header. Read moreSource§fn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
fn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
Content-Type. Read moreSource§fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
Content-Type header as a MIME type. Read moreCookie headers. Read moreSource§impl<St> Resource<Url> for WebRequest<St>
impl<St> Resource<Url> for WebRequest<St>
Source§impl<S, St, In> Service<St, WebRequest<In>> for WebMiddleware<S, St>where
S: Service<St, WebRequest<In>, Res = WebResponse>,
S::Error: WebResponseError<St, St::Error>,
St: State,
impl<S, St, In> Service<St, WebRequest<In>> for WebMiddleware<S, St>where
S: Service<St, WebRequest<In>, Res = WebResponse>,
S::Error: WebResponseError<St, St::Error>,
St: State,
Source§type Res = WebResponse
type Res = WebResponse
Source§type Error = WebError<St, <St as State>::Error>
type Error = WebError<St, <St as State>::Error>
Source§async fn call(
&self,
req: WebRequest<In>,
ctx: Ctx<'_, Self, St>,
) -> Result<Self::Res, Self::Error>
async fn call( &self, req: WebRequest<In>, ctx: Ctx<'_, Self, St>, ) -> Result<Self::Res, Self::Error>
Source§async fn ready(&self, ctx: Ctx<'_, Self, St>) -> Result<(), Self::Error>
async fn ready(&self, ctx: Ctx<'_, Self, St>) -> Result<(), Self::Error>
Source§fn map<F, Res>(self, f: F) -> ServiceChain<Map<F, Self, Res>, St, Req>
fn map<F, Res>(self, f: F) -> ServiceChain<Map<F, Self, Res>, St, Req>
Source§fn map_err<F, E>(self, f: F) -> ServiceChain<MapErr<F, Self, E>, St, Req>
fn map_err<F, E>(self, f: F) -> ServiceChain<MapErr<F, Self, E>, St, Req>
Source§impl<St: State, In> Service<St, WebRequest<In>> for Filter<St, In>
impl<St: State, In> Service<St, WebRequest<In>> for Filter<St, In>
Source§type Res = WebRequest<In>
type Res = WebRequest<In>
Source§type Error = WebError<St, <St as State>::Error>
type Error = WebError<St, <St as State>::Error>
Source§async fn call(
&self,
req: WebRequest<In>,
_: Ctx<'_, Self, St>,
) -> Result<Self::Res, Self::Error>
async fn call( &self, req: WebRequest<In>, _: Ctx<'_, Self, St>, ) -> Result<Self::Res, Self::Error>
Source§async fn ready(&self, ctx: Ctx<'_, Self, St>) -> Result<(), Self::Error>
async fn ready(&self, ctx: Ctx<'_, Self, St>) -> Result<(), Self::Error>
Source§fn map<F, Res>(self, f: F) -> ServiceChain<Map<F, Self, Res>, St, Req>
fn map<F, Res>(self, f: F) -> ServiceChain<Map<F, Self, Res>, St, Req>
Source§fn map_err<F, E>(self, f: F) -> ServiceChain<MapErr<F, Self, E>, St, Req>
fn map_err<F, E>(self, f: F) -> ServiceChain<MapErr<F, Self, E>, St, Req>
Source§impl<St: State, In: 'static> ServiceFactory<St, WebRequest<In>> for Route<St, In>
impl<St: State, In: 'static> ServiceFactory<St, WebRequest<In>> for Route<St, In>
Source§type Res = WebResponse
type Res = WebResponse
Source§async fn create(&self, _: &St) -> Result<Self::Service, Self::InitError>
async fn create(&self, _: &St) -> Result<Self::Service, Self::InitError>
Source§async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
Pipeline.Source§fn map<F, Res>(
self,
f: F,
) -> ServiceChainFactory<MapFactory<F, Self, Res>, St, Req>
fn map<F, Res>( self, f: F, ) -> ServiceChainFactory<MapFactory<F, Self, Res>, St, Req>
Source§fn map_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapErrFactory<F, Self, E>, St, Req>
fn map_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapErrFactory<F, Self, E>, St, Req>
Source§fn map_init_err<F, E>(
self,
f: F,
) -> ServiceChainFactory<MapInitErr<F, Self, E>, St, Req>
fn map_init_err<F, E>( self, f: F, ) -> ServiceChainFactory<MapInitErr<F, Self, E>, St, Req>
Source§fn and_then<U, F>(
self,
f: F,
) -> ServiceChainFactory<AndThenFactory<Self, U>, St, Req>where
Self: Sized,
U: ServiceFactory<St, Self::Res, Error = Self::Error, InitError = Self::InitError>,
F: IntoServiceFactory<U, St, Self::Res>,
fn and_then<U, F>(
self,
f: F,
) -> ServiceChainFactory<AndThenFactory<Self, U>, St, Req>where
Self: Sized,
U: ServiceFactory<St, Self::Res, Error = Self::Error, InitError = Self::InitError>,
F: IntoServiceFactory<U, St, Self::Res>,
Source§impl<St: State, In> ServiceFactory<St, WebRequest<In>> for Filter<St, In>
impl<St: State, In> ServiceFactory<St, WebRequest<In>> for Filter<St, In>
Source§type Res = WebRequest<In>
type Res = WebRequest<In>
Source§async fn create(&self, _: &St) -> Result<Self::Service, Self::InitError>
async fn create(&self, _: &St) -> Result<Self::Service, Self::InitError>
Source§async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
async fn pipeline(
&self,
st: St,
) -> Result<Pipeline<Req, Self::Res, Self::Error>, Self::InitError>where
Self: 'static,
St: 'static,
Req: 'static,
Pipeline.