Struct actix_web::dev::ServiceRequest
source · pub struct ServiceRequest { /* private fields */ }
Expand description
A service level request wrapper.
Allows mutable access to request’s internal structures.
Implementations§
source§impl ServiceRequest
impl ServiceRequest
sourcepub fn into_parts(self) -> (HttpRequest, Payload)
pub fn into_parts(self) -> (HttpRequest, Payload)
Deconstruct ServiceRequest
into inner parts.
sourcepub fn parts_mut(&mut self) -> (&mut HttpRequest, &mut Payload)
pub fn parts_mut(&mut self) -> (&mut HttpRequest, &mut Payload)
Returns mutable accessors to inner parts.
sourcepub fn parts(&self) -> (&HttpRequest, &Payload)
pub fn parts(&self) -> (&HttpRequest, &Payload)
Returns immutable accessors to inner parts.
sourcepub fn request(&self) -> &HttpRequest
pub fn request(&self) -> &HttpRequest
Returns immutable accessor to inner HttpRequest
.
sourcepub fn extract<T>(&mut self) -> <T as FromRequest>::Futurewhere
T: FromRequest,
pub fn extract<T>(&mut self) -> <T as FromRequest>::Futurewhere
T: FromRequest,
Derives a type from this request using an extractor.
Returns the T
extractor’s Future
type which can be await
ed. This is particularly handy
when you want to use an extractor in a middleware implementation.
§Examples
use actix_web::{
dev::{ServiceRequest, ServiceResponse},
web::Path, Error
};
async fn my_helper(mut srv_req: ServiceRequest) -> Result<ServiceResponse, Error> {
let path = srv_req.extract::<Path<(String, u32)>>().await?;
// [...]
}
sourcepub fn from_parts(req: HttpRequest, payload: Payload) -> Self
pub fn from_parts(req: HttpRequest, payload: Payload) -> Self
Construct request from parts.
sourcepub fn from_request(req: HttpRequest) -> Self
pub fn from_request(req: HttpRequest) -> Self
Construct ServiceRequest
with no payload from given HttpRequest
.
sourcepub fn into_response<B, R: Into<Response<B>>>(
self,
res: R,
) -> ServiceResponse<B>
pub fn into_response<B, R: Into<Response<B>>>( self, res: R, ) -> ServiceResponse<B>
Create ServiceResponse
from this request and given response.
sourcepub fn error_response<E: Into<Error>>(self, err: E) -> ServiceResponse
pub fn error_response<E: Into<Error>>(self, err: E) -> ServiceResponse
Create ServiceResponse
from this request and given error.
sourcepub fn head(&self) -> &RequestHead
pub fn head(&self) -> &RequestHead
Returns a reference to the request head.
sourcepub fn head_mut(&mut self) -> &mut RequestHead
pub fn head_mut(&mut self) -> &mut RequestHead
Returns a mutable reference to the request head.
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Returns a mutable reference to request headers.
sourcepub fn query_string(&self) -> &str
pub fn query_string(&self) -> &str
Counterpart to HttpRequest::query_string
.
sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Returns peer’s socket address.
See HttpRequest::peer_addr
for more details.
sourcepub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
Returns a reference to connection info.
sourcepub fn match_info(&self) -> &Path<Url>
pub fn match_info(&self) -> &Path<Url>
Counterpart to HttpRequest::match_info
.
sourcepub fn match_info_mut(&mut self) -> &mut Path<Url>
pub fn match_info_mut(&mut self) -> &mut Path<Url>
Returns a mutable reference to the path match information.
sourcepub fn match_name(&self) -> Option<&str>
pub fn match_name(&self) -> Option<&str>
Counterpart to HttpRequest::match_name
.
sourcepub fn match_pattern(&self) -> Option<String>
pub fn match_pattern(&self) -> Option<String>
Counterpart to HttpRequest::match_pattern
.
sourcepub fn resource_map(&self) -> &ResourceMap
pub fn resource_map(&self) -> &ResourceMap
Returns a reference to the application’s resource map.
Counterpart to HttpRequest::resource_map
.
sourcepub fn app_config(&self) -> &AppConfig
pub fn app_config(&self) -> &AppConfig
Counterpart to HttpRequest::app_config
.
sourcepub fn app_data<T: 'static>(&self) -> Option<&T>
pub fn app_data<T: 'static>(&self) -> Option<&T>
Counterpart to HttpRequest::app_data
.
sourcepub fn conn_data<T: 'static>(&self) -> Option<&T>
pub fn conn_data<T: 'static>(&self) -> Option<&T>
Counterpart to HttpRequest::conn_data
.
Return request cookies.
Return request cookie.
sourcepub fn set_payload(&mut self, payload: Payload)
pub fn set_payload(&mut self, payload: Payload)
Set request payload.
sourcepub fn add_data_container(&mut self, extensions: Rc<Extensions>)
pub fn add_data_container(&mut self, extensions: Rc<Extensions>)
Add data container to request’s resolution set.
In middleware, prefer extensions_mut
for request-local
data since it is assumed that the same app data is presented for every request.
sourcepub fn guard_ctx(&self) -> GuardContext<'_>
pub fn guard_ctx(&self) -> GuardContext<'_>
Creates a context object for use with a routing guard.
Trait Implementations§
source§impl Debug for ServiceRequest
impl Debug for ServiceRequest
source§impl HttpMessage for ServiceRequest
impl HttpMessage for ServiceRequest
§type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>>>>
type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>>>>
source§fn extensions(&self) -> Ref<'_, Extensions>
fn extensions(&self) -> Ref<'_, Extensions>
source§fn extensions_mut(&self) -> RefMut<'_, Extensions>
fn extensions_mut(&self) -> RefMut<'_, Extensions>
source§fn take_payload(&mut self) -> Payload<Self::Stream>
fn take_payload(&mut self) -> Payload<Self::Stream>
source§fn content_type(&self) -> &str
fn content_type(&self) -> &str
source§fn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
fn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
source§impl Resource for ServiceRequest
impl Resource for ServiceRequest
source§impl<B> Service<ServiceRequest> for Next<B>
impl<B> Service<ServiceRequest> for Next<B>
§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
§type Future = Pin<Box<dyn Future<Output = Result<<Next<B> as Service<ServiceRequest>>::Response, <Next<B> as Service<ServiceRequest>>::Error>>>>
type Future = Pin<Box<dyn Future<Output = Result<<Next<B> as Service<ServiceRequest>>::Response, <Next<B> as Service<ServiceRequest>>::Error>>>>
source§impl ServiceFactory<ServiceRequest> for Route
impl ServiceFactory<ServiceRequest> for Route
§type Response = ServiceResponse
type Response = ServiceResponse
§type Future = Pin<Box<dyn Future<Output = Result<<Route as ServiceFactory<ServiceRequest>>::Service, <Route as ServiceFactory<ServiceRequest>>::InitError>>>>
type Future = Pin<Box<dyn Future<Output = Result<<Route as ServiceFactory<ServiceRequest>>::Service, <Route as ServiceFactory<ServiceRequest>>::InitError>>>>
Service
instance.g