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 awaited. 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
Source§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>
Source§type Response = ServiceResponse<B>
 
type Response = ServiceResponse<B>
Source§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
Source§type Response = ServiceResponse
 
type Response = ServiceResponse
Source§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.gSource§fn new_service(&self, _: ()) -> Self::Future
 
fn new_service(&self, _: ()) -> Self::Future
Source§impl<S, B> Transform<S, ServiceRequest> for Compress
 
impl<S, B> Transform<S, ServiceRequest> for Compress
Source§type Response = ServiceResponse<EitherBody<Encoder<B>>>
 
type Response = ServiceResponse<EitherBody<Encoder<B>>>
Source§type Future = Ready<Result<<Compress as Transform<S, ServiceRequest>>::Transform, <Compress as Transform<S, ServiceRequest>>::InitError>>
 
type Future = Ready<Result<<Compress as Transform<S, ServiceRequest>>::Transform, <Compress as Transform<S, ServiceRequest>>::InitError>>
Source§fn new_transform(&self, service: S) -> Self::Future
 
fn new_transform(&self, service: S) -> Self::Future
Source§impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders
 
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders
Source§type Response = ServiceResponse<B>
 
type Response = ServiceResponse<B>
Source§type Transform = DefaultHeadersMiddleware<S>
 
type Transform = DefaultHeadersMiddleware<S>
TransformService value created by this factorySource§type Future = Ready<Result<<DefaultHeaders as Transform<S, ServiceRequest>>::Transform, <DefaultHeaders as Transform<S, ServiceRequest>>::InitError>>
 
type Future = Ready<Result<<DefaultHeaders as Transform<S, ServiceRequest>>::Transform, <DefaultHeaders as Transform<S, ServiceRequest>>::InitError>>
Source§fn new_transform(&self, service: S) -> Self::Future
 
fn new_transform(&self, service: S) -> Self::Future
Source§impl<S, B> Transform<S, ServiceRequest> for ErrorHandlers<B>where
    S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
    S::Future: 'static,
    B: 'static,
 
impl<S, B> Transform<S, ServiceRequest> for ErrorHandlers<B>where
    S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
    S::Future: 'static,
    B: 'static,
Source§type Response = ServiceResponse<EitherBody<B>>
 
type Response = ServiceResponse<EitherBody<B>>
Source§type Transform = ErrorHandlersMiddleware<S, B>
 
type Transform = ErrorHandlersMiddleware<S, B>
TransformService value created by this factorySource§type Future = Pin<Box<dyn Future<Output = Result<<ErrorHandlers<B> as Transform<S, ServiceRequest>>::Transform, <ErrorHandlers<B> as Transform<S, ServiceRequest>>::InitError>>>>
 
type Future = Pin<Box<dyn Future<Output = Result<<ErrorHandlers<B> as Transform<S, ServiceRequest>>::Transform, <ErrorHandlers<B> as Transform<S, ServiceRequest>>::InitError>>>>
Source§fn new_transform(&self, service: S) -> Self::Future
 
fn new_transform(&self, service: S) -> Self::Future
Source§impl<S, B> Transform<S, ServiceRequest> for Logger
 
impl<S, B> Transform<S, ServiceRequest> for Logger
Source§type Response = ServiceResponse<StreamLog<B>>
 
type Response = ServiceResponse<StreamLog<B>>
Source§type Future = Ready<Result<<Logger as Transform<S, ServiceRequest>>::Transform, <Logger as Transform<S, ServiceRequest>>::InitError>>
 
type Future = Ready<Result<<Logger as Transform<S, ServiceRequest>>::Transform, <Logger as Transform<S, ServiceRequest>>::InitError>>
Source§fn new_transform(&self, service: S) -> Self::Future
 
fn new_transform(&self, service: S) -> Self::Future
Source§impl<S, B> Transform<S, ServiceRequest> for NormalizePath
 
impl<S, B> Transform<S, ServiceRequest> for NormalizePath
Source§type Response = ServiceResponse<B>
 
type Response = ServiceResponse<B>
Source§type Transform = NormalizePathNormalization<S>
 
type Transform = NormalizePathNormalization<S>
TransformService value created by this factorySource§type Future = Ready<Result<<NormalizePath as Transform<S, ServiceRequest>>::Transform, <NormalizePath as Transform<S, ServiceRequest>>::InitError>>
 
type Future = Ready<Result<<NormalizePath as Transform<S, ServiceRequest>>::Transform, <NormalizePath as Transform<S, ServiceRequest>>::InitError>>
Source§fn new_transform(&self, service: S) -> Self::Future
 
fn new_transform(&self, service: S) -> Self::Future
Auto Trait Implementations§
impl Freeze for ServiceRequest
impl !RefUnwindSafe for ServiceRequest
impl !Send for ServiceRequest
impl !Sync for ServiceRequest
impl Unpin for ServiceRequest
impl !UnwindSafe for ServiceRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
 
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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