Struct ntex::web::WebRequest

source ·
pub struct WebRequest<Err> { /* private fields */ }
Expand description

An service http request

WebRequest allows mutable access to request’s internal structures

Implementations§

source§

impl<Err: ErrorRenderer> WebRequest<Err>

source

pub fn render_error<E: WebResponseError<Err>>(self, err: E) -> WebResponse

Create web response for error

source

pub fn error_response<E: Into<Err::Container>>(self, err: E) -> WebResponse

Create web response for error

source§

impl<Err> WebRequest<Err>

source

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

Deconstruct request into parts

source

pub fn from_parts( req: HttpRequest, pl: Payload ) -> Result<Self, (HttpRequest, Payload)>

Construct request from parts.

WebRequest can be re-constructed only if req hasnt been cloned.

source

pub fn from_request(req: HttpRequest) -> Result<Self, HttpRequest>

Construct request from request.

HttpRequest implements Clone trait via Rc type. WebRequest can be re-constructed only if rc’s strong pointers count eq 1 and weak pointers count is 0.

source

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

Create web response

source

pub fn io(&self) -> Option<&IoRef>

Io reference for current connection

source

pub fn head(&self) -> &RequestHead

This method returns reference to the request head

source

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

This method returns reference to the request head

source

pub fn uri(&self) -> &Uri

Request’s uri.

source

pub fn method(&self) -> &Method

Read the Request method.

source

pub fn version(&self) -> Version

Read the Request Version.

source

pub fn headers(&self) -> &HeaderMap

Returns request’s headers.

source

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

Returns mutable request’s headers.

source

pub fn path(&self) -> &str

The target path of this Request.

source

pub fn query_string(&self) -> &str

The query string in the URL.

E.g., id=10

source

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.

source

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

Get ConnectionInfo for the current request.

source

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

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.

source

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

Get a mutable reference to the Path parameters.

source

pub fn resource_map(&self) -> &ResourceMap

Get a reference to a ResourceMap of current application.

source

pub fn app_config(&self) -> &AppConfig

Service configuration

source

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

Get an application state stored with App::app_state() method during application configuration.

To get state stored with App::state() use web::types::State<T> as type.

source

pub fn take_payload(&mut self) -> Payload

Get request’s payload

source

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

Set request payload.

source

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

Request extensions

source

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

Mutable reference to a the request’s extensions

Trait Implementations§

source§

impl<Err: ErrorRenderer> Debug for WebRequest<Err>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Err> HttpMessage for WebRequest<Err>

source§

fn message_headers(&self) -> &HeaderMap

Returns Request’s headers.

source§

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

Request extensions

source§

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

Mutable reference to a the request’s extensions

source§

fn content_type(&self) -> &str

Read the request content type. If request does not contain Content-Type header, empty str get 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, DecodeError>

Check if request has chunked transfer encoding
source§

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

Load request cookies.
source§

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

Return request cookie.
source§

impl<Err> Resource<Uri> for WebRequest<Err>

source§

fn path(&self) -> &str

source§

fn resource_path(&mut self) -> &mut Path<Uri>

source§

impl<Err: ErrorRenderer> ServiceFactory<WebRequest<Err>> for Route<Err>

§

type Response = WebResponse

Responses given by the created services.
§

type Error = <Err as ErrorRenderer>::Container

Errors produced by the created services.
§

type InitError = ()

Errors potentially raised while building a service.
§

type Service = RouteService<Err>

The kind of Service created by this factory.
source§

async fn create(&self, _: ()) -> Result<RouteService<Err>, ()>

Create and return a new service value asynchronously.
source§

async fn pipeline( &self, cfg: Cfg ) -> Result<Pipeline<Self::Service>, Self::InitError>
where Self: Sized,

Create and return a new service value asynchronously and wrap into a container
source§

fn map<F, Res>( self, f: F ) -> ServiceChainFactory<MapFactory<Self, F, Req, Res, Cfg>, Req, Cfg>
where Self: Sized, F: Fn(Self::Response) -> Res + Clone,

Map this service’s output to a different type, returning a new service of the resulting type.
source§

fn map_err<F, E>( self, f: F ) -> ServiceChainFactory<MapErrFactory<Self, Req, Cfg, F, E>, Req, Cfg>
where Self: Sized, F: Fn(Self::Error) -> E + Clone,

Map this service’s error to a different error, returning a new service.
source§

fn map_init_err<F, E>( self, f: F ) -> ServiceChainFactory<MapInitErr<Self, Req, Cfg, F, E>, Req, Cfg>
where Self: Sized, F: Fn(Self::InitError) -> E + Clone,

Map this factory’s init error to a different error, returning a new service.

Auto Trait Implementations§

§

impl<Err> Freeze for WebRequest<Err>

§

impl<Err> !RefUnwindSafe for WebRequest<Err>

§

impl<Err> !Send for WebRequest<Err>

§

impl<Err> !Sync for WebRequest<Err>

§

impl<Err> Unpin for WebRequest<Err>
where Err: Unpin,

§

impl<Err> !UnwindSafe for WebRequest<Err>

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