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

source

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

Deconstruct ServiceRequest into inner parts.

source

pub fn parts_mut(&mut self) -> (&mut HttpRequest, &mut Payload)

Returns mutable accessors to inner parts.

source

pub fn parts(&self) -> (&HttpRequest, &Payload)

Returns immutable accessors to inner parts.

source

pub fn request(&self) -> &HttpRequest

Returns immutable accessor to inner HttpRequest.

source

pub fn extract<T>(&mut self) -> <T as FromRequest>::Future
where 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?;
    // [...]
}
source

pub fn from_parts(req: HttpRequest, payload: Payload) -> Self

Construct request from parts.

source

pub fn from_request(req: HttpRequest) -> Self

Construct ServiceRequest with no payload from given HttpRequest.

source

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

Create ServiceResponse from this request and given response.

source

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

Create ServiceResponse from this request and given error.

source

pub fn head(&self) -> &RequestHead

Returns a reference to the request head.

source

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

Returns a mutable reference to the request head.

source

pub fn uri(&self) -> &Uri

Returns the request URI.

source

pub fn method(&self) -> &Method

Returns the request method.

source

pub fn version(&self) -> Version

Returns the request version.

source

pub fn headers(&self) -> &HeaderMap

Returns a reference to request headers.

source

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

Returns a mutable reference to request headers.

source

pub fn path(&self) -> &str

Returns request path.

source

pub fn query_string(&self) -> &str

Counterpart to HttpRequest::query_string.

source

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

Returns peer’s socket address.

See HttpRequest::peer_addr for more details.

source

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

Returns a reference to connection info.

source

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

Counterpart to HttpRequest::match_info.

source

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

Returns a mutable reference to the path match information.

source

pub fn match_name(&self) -> Option<&str>

Counterpart to HttpRequest::match_name.

source

pub fn match_pattern(&self) -> Option<String>

source

pub fn resource_map(&self) -> &ResourceMap

Returns a reference to the application’s resource map. Counterpart to HttpRequest::resource_map.

source

pub fn app_config(&self) -> &AppConfig

Counterpart to HttpRequest::app_config.

source

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

Counterpart to HttpRequest::app_data.

source

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

Counterpart to HttpRequest::conn_data.

source

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

Return request cookies.

source

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

Return request cookie.

source

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

Set request payload.

source

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.

source

pub fn guard_ctx(&self) -> GuardContext<'_>

Creates a context object for use with a routing guard.

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

§

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

Type of message payload stream
source§

fn headers(&self) -> &HeaderMap

Read the message headers.
source§

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

Returns a reference to the request-local data/extensions container.
source§

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

Returns a mutable reference to the request-local data/extensions container.
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 did not contain a Content-Type header, an empty string is 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§

impl Resource for ServiceRequest

§

type Path = Url

Type of resource’s path returned in resource_path.
source§

fn resource_path(&mut self) -> &mut Path<Self::Path>

source§

impl<B> Service<ServiceRequest> for Next<B>

§

type Response = ServiceResponse<B>

Responses given by the service.
§

type Error = Error

Errors produced by the service when polling readiness or executing call.
§

type Future = Pin<Box<dyn Future<Output = Result<<Next<B> as Service<ServiceRequest>>::Response, <Next<B> as Service<ServiceRequest>>::Error>>>>

The future response value.
source§

fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Returns Ready when the service is able to process requests. Read more
source§

fn call(&self, req: ServiceRequest) -> Self::Future

Process the request and return the response asynchronously. Read more
source§

impl ServiceFactory<ServiceRequest> for Route

§

type Response = ServiceResponse

Responses given by the created services.
§

type Error = Error

Errors produced by the created services.
§

type Config = ()

Service factory configuration.
§

type Service = RouteService

The kind of Service created by this factory.
§

type InitError = ()

Errors potentially raised while building a service.
§

type Future = Pin<Box<dyn Future<Output = Result<<Route as ServiceFactory<ServiceRequest>>::Service, <Route as ServiceFactory<ServiceRequest>>::InitError>>>>

The future of the Service instance.g
source§

fn new_service(&self, _: ()) -> Self::Future

Create and return a new service asynchronously.
source§

impl<S, B> Transform<S, ServiceRequest> for Compress
where B: MessageBody, S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>,

§

type Response = ServiceResponse<EitherBody<Encoder<B>>>

Responses produced by the service.
§

type Error = Error

Errors produced by the service.
§

type Transform = CompressMiddleware<S>

The TransformService value created by this factory
§

type InitError = ()

Errors produced while building a transform service.
§

type Future = Ready<Result<<Compress as Transform<S, ServiceRequest>>::Transform, <Compress as Transform<S, ServiceRequest>>::InitError>>

The future response value.
source§

fn new_transform(&self, service: S) -> Self::Future

Creates and returns a new Transform component, asynchronously
source§

impl<S, B> Transform<S, ServiceRequest> for DefaultHeaders
where S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>, S::Future: 'static,

§

type Response = ServiceResponse<B>

Responses produced by the service.
§

type Error = Error

Errors produced by the service.
§

type Transform = DefaultHeadersMiddleware<S>

The TransformService value created by this factory
§

type InitError = ()

Errors produced while building a transform service.
§

type Future = Ready<Result<<DefaultHeaders as Transform<S, ServiceRequest>>::Transform, <DefaultHeaders as Transform<S, ServiceRequest>>::InitError>>

The future response value.
source§

fn new_transform(&self, service: S) -> Self::Future

Creates and returns a new Transform component, asynchronously
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,

§

type Response = ServiceResponse<EitherBody<B>>

Responses produced by the service.
§

type Error = Error

Errors produced by the service.
§

type Transform = ErrorHandlersMiddleware<S, B>

The TransformService value created by this factory
§

type InitError = ()

Errors produced while building a transform service.
§

type Future = Pin<Box<dyn Future<Output = Result<<ErrorHandlers<B> as Transform<S, ServiceRequest>>::Transform, <ErrorHandlers<B> as Transform<S, ServiceRequest>>::InitError>>>>

The future response value.
source§

fn new_transform(&self, service: S) -> Self::Future

Creates and returns a new Transform component, asynchronously
source§

impl<S, B> Transform<S, ServiceRequest> for Logger
where S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>, B: MessageBody,

§

type Response = ServiceResponse<StreamLog<B>>

Responses produced by the service.
§

type Error = Error

Errors produced by the service.
§

type Transform = LoggerMiddleware<S>

The TransformService value created by this factory
§

type InitError = ()

Errors produced while building a transform service.
§

type Future = Ready<Result<<Logger as Transform<S, ServiceRequest>>::Transform, <Logger as Transform<S, ServiceRequest>>::InitError>>

The future response value.
source§

fn new_transform(&self, service: S) -> Self::Future

Creates and returns a new Transform component, asynchronously
source§

impl<S, B> Transform<S, ServiceRequest> for NormalizePath
where S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>, S::Future: 'static,

§

type Response = ServiceResponse<B>

Responses produced by the service.
§

type Error = Error

Errors produced by the service.
§

type Transform = NormalizePathNormalization<S>

The TransformService value created by this factory
§

type InitError = ()

Errors produced while building a transform service.
§

type Future = Ready<Result<<NormalizePath as Transform<S, ServiceRequest>>::Transform, <NormalizePath as Transform<S, ServiceRequest>>::InitError>>

The future response value.
source§

fn new_transform(&self, service: S) -> Self::Future

Creates and returns a new Transform component, asynchronously

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more