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
sourceimpl ServiceRequest
impl ServiceRequest
sourcepub fn into_parts(self) -> (HttpRequest, Payload)
pub fn into_parts(self) -> (HttpRequest, Payload)
Deconstruct request into parts
sourcepub fn parts_mut(&mut self) -> (&mut HttpRequest, &mut Payload)
pub fn parts_mut(&mut self) -> (&mut HttpRequest, &mut Payload)
Get mutable access to inner HttpRequest
and Payload
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 request from request.
The returned ServiceRequest
would have no payload.
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 service response
sourcepub fn error_response<E: Into<Error>>(self, err: E) -> ServiceResponse
pub fn error_response<E: Into<Error>>(self, err: E) -> ServiceResponse
Create service response for error
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 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
Counterpart to HttpRequest::query_string
.
sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Peer socket address.
Peer address is the directly connected peer’s socket address. If a proxy is used in front of the Actix Web server, then it would be address of this proxy.
To get client connection information ConnectionInfo
should be used.
Will only return None when called in unit tests.
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_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 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) -> &AppConfig
pub fn app_config(&self) -> &AppConfig
Service configuration
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
.
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.
Trait Implementations
sourceimpl Debug for ServiceRequest
impl Debug for ServiceRequest
sourceimpl HttpMessage for ServiceRequest
impl HttpMessage for ServiceRequest
sourcefn extensions(&self) -> Ref<'_, Extensions>
fn extensions(&self) -> Ref<'_, Extensions>
Request extensions
sourcefn extensions_mut(&self) -> RefMut<'_, Extensions>
fn extensions_mut(&self) -> RefMut<'_, Extensions>
Mutable reference to a the request’s extensions
type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>> + 'static, Global>>
type Stream = Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>> + 'static, Global>>
Type of message payload stream
sourcefn take_payload(&mut self) -> Payload<Self::Stream>
fn take_payload(&mut self) -> Payload<Self::Stream>
Message payload stream
sourcefn content_type(&self) -> &str
fn content_type(&self) -> &str
Read the request content type. If request did not contain a Content-Type header, an empty string is returned. Read more
sourcefn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
fn encoding(&self) -> Result<&'static Encoding, ContentTypeError>
Get content type encoding Read more
sourcefn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
Convert the request content type to a known mime type.
sourcefn chunked(&self) -> Result<bool, ParseError>
fn chunked(&self) -> Result<bool, ParseError>
Check if request has chunked transfer encoding.
sourceimpl Resource<Url> for ServiceRequest
impl Resource<Url> for ServiceRequest
fn resource_path(&mut self) -> &mut Path<Url>
sourceimpl ServiceFactory<ServiceRequest> for Route
impl ServiceFactory<ServiceRequest> for Route
type Response = ServiceResponse<BoxBody>
type Response = ServiceResponse<BoxBody>
Responses given by the created services.
type Service = RouteService
type Service = RouteService
The kind of Service
created by this factory.
type Future = Pin<Box<dyn Future<Output = Result<<Route as ServiceFactory<ServiceRequest>>::Service, <Route as ServiceFactory<ServiceRequest>>::InitError>> + 'static, Global>>
type Future = Pin<Box<dyn Future<Output = Result<<Route as ServiceFactory<ServiceRequest>>::Service, <Route as ServiceFactory<ServiceRequest>>::InitError>> + 'static, Global>>
The future of the Service
instance.g
sourcefn new_service(&self, _: ()) -> Self::Future
fn new_service(&self, _: ()) -> Self::Future
Create and return a new service asynchronously.
sourceimpl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
type Transform = DefaultHeadersMiddleware<S>
type Transform = DefaultHeadersMiddleware<S>
The TransformService
value created by this factory
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>>
The future response value.
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
sourceimpl<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,
type Response = ServiceResponse<EitherBody<B, BoxBody>>
type Response = ServiceResponse<EitherBody<B, BoxBody>>
Responses produced by the service.
type Transform = ErrorHandlersMiddleware<S, B>
type Transform = ErrorHandlersMiddleware<S, B>
The TransformService
value created by this factory
type Future = Pin<Box<dyn Future<Output = Result<<ErrorHandlers<B> as Transform<S, ServiceRequest>>::Transform, <ErrorHandlers<B> as Transform<S, ServiceRequest>>::InitError>> + 'static, Global>>
type Future = Pin<Box<dyn Future<Output = Result<<ErrorHandlers<B> as Transform<S, ServiceRequest>>::Transform, <ErrorHandlers<B> as Transform<S, ServiceRequest>>::InitError>> + 'static, Global>>
The future response value.
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
sourceimpl<S, B> Transform<S, ServiceRequest> for Logger where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody,
impl<S, B> Transform<S, ServiceRequest> for Logger where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody,
type Response = ServiceResponse<StreamLog<B>>
type Response = ServiceResponse<StreamLog<B>>
Responses produced by the service.
type Transform = LoggerMiddleware<S>
type Transform = LoggerMiddleware<S>
The TransformService
value created by this factory
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>>
The future response value.
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
sourceimpl<S, B> Transform<S, ServiceRequest> for NormalizePath where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
impl<S, B> Transform<S, ServiceRequest> for NormalizePath where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses produced by the service.
type Transform = NormalizePathNormalization<S>
type Transform = NormalizePathNormalization<S>
The TransformService
value created by this factory
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>>
The future response value.
sourcefn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations
impl !RefUnwindSafe for ServiceRequest
impl !Send for ServiceRequest
impl !Sync for ServiceRequest
impl Unpin for ServiceRequest
impl !UnwindSafe for ServiceRequest
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more