Struct actix_web::HttpRequest
source · pub struct HttpRequest<S = ()> { /* private fields */ }
Expand description
An HTTP Request
Implementations
sourceimpl<S> HttpRequest<S>
impl<S> HttpRequest<S>
sourcepub fn drop_state(&self) -> HttpRequest
pub fn drop_state(&self) -> HttpRequest
Construct new http request with empty state.
sourcepub fn extensions(&self) -> Ref<'_, Extensions>
pub fn extensions(&self) -> Ref<'_, Extensions>
Request extensions
sourcepub fn extensions_mut(&self) -> RefMut<'_, Extensions>
pub fn extensions_mut(&self) -> RefMut<'_, Extensions>
Mutable reference to a the request’s extensions
sourcepub fn response(&self, status: StatusCode, body: Body) -> HttpResponse
pub fn response(&self, status: StatusCode, body: Body) -> HttpResponse
Create http response
sourcepub fn build_response(&self, status: StatusCode) -> HttpResponseBuilder
pub fn build_response(&self, status: StatusCode) -> HttpResponseBuilder
Create http response builder
sourcepub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
Get ConnectionInfo for the correct request.
sourcepub fn url_for<U, I>(
&self,
name: &str,
elements: U
) -> Result<Url, UrlGenerationError>where
U: IntoIterator<Item = I>,
I: AsRef<str>,
pub fn url_for<U, I>(
&self,
name: &str,
elements: U
) -> Result<Url, UrlGenerationError>where
U: IntoIterator<Item = I>,
I: AsRef<str>,
Generate url for named resource
fn index(req: HttpRequest) -> HttpResponse {
let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource
HttpResponse::Ok().into()
}
fn main() {
let app = App::new()
.resource("/test/{one}/{two}/{three}", |r| {
r.name("foo"); // <- set resource name, then it could be used in `url_for`
r.method(http::Method::GET).f(|_| HttpResponse::Ok());
})
.finish();
}
sourcepub fn url_for_static(&self, name: &str) -> Result<Url, UrlGenerationError>
pub fn url_for_static(&self, name: &str) -> Result<Url, UrlGenerationError>
Generate url for named resource
This method is similar to HttpRequest::url_for()
but it can be used
for urls that do not contain variable parts.
sourcepub fn resource(&self) -> &ResourceInfo
pub fn resource(&self) -> &ResourceInfo
This method returns reference to current ResourceInfo
object.
sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Peer socket address
Peer address is actual socket address, if proxy is used in front of actix http server, then peer address would be address of this proxy.
To get client connection information connection_info()
method should
be used.
sourcepub fn query_string(&self) -> &str
pub fn query_string(&self) -> &str
The query string in the URL.
E.g., id=10
Load request cookies.
Return request cookie.
sourcepub fn match_info(&self) -> &Params
pub fn match_info(&self) -> &Params
Get a reference to the Params object.
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 set_read_buffer_capacity(&mut self, cap: usize)
pub fn set_read_buffer_capacity(&mut self, cap: usize)
Set read buffer capacity
Default buffer capacity is 32Kb.
Methods from Deref<Target = Request>
sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Peer socket address
Peer address is actual socket address, if proxy is used in front of actix http server, then peer address would be address of this proxy.
To get client connection information connection_info()
method should
be used.
sourcepub fn keep_alive(&self) -> bool
pub fn keep_alive(&self) -> bool
Checks if a connection should be kept alive.
sourcepub fn extensions(&self) -> Ref<'_, Extensions>
pub fn extensions(&self) -> Ref<'_, Extensions>
Request extensions
sourcepub fn extensions_mut(&self) -> RefMut<'_, Extensions>
pub fn extensions_mut(&self) -> RefMut<'_, Extensions>
Mutable reference to a the request’s extensions
sourcepub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
pub fn connection_info(&self) -> Ref<'_, ConnectionInfo>
Get ConnectionInfo for the correct request.
sourcepub fn stream_extensions(&self) -> Option<&Extensions>
pub fn stream_extensions(&self) -> Option<&Extensions>
Io stream extensions
sourcepub fn server_settings(&self) -> &ServerSettings
pub fn server_settings(&self) -> &ServerSettings
Server settings
Trait Implementations
sourceimpl<S> Clone for HttpRequest<S>
impl<S> Clone for HttpRequest<S>
sourcefn clone(&self) -> HttpRequest<S>
fn clone(&self) -> HttpRequest<S>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl<S> Debug for HttpRequest<S>
impl<S> Debug for HttpRequest<S>
sourceimpl<S> Deref for HttpRequest<S>
impl<S> Deref for HttpRequest<S>
sourceimpl<S> Drop for HttpRequest<S>
impl<S> Drop for HttpRequest<S>
sourceimpl<'a, S: 'static> From<&'a HttpRequest<S>> for ClientRequestBuilder
impl<'a, S: 'static> From<&'a HttpRequest<S>> for ClientRequestBuilder
Create ClientRequestBuilder
from HttpRequest
It is useful for proxy requests. This implementation copies all request headers and the method.
sourcefn from(req: &'a HttpRequest<S>) -> ClientRequestBuilder
fn from(req: &'a HttpRequest<S>) -> ClientRequestBuilder
sourceimpl<'a, S> From<&'a HttpRequest<S>> for HttpResponseBuilder
impl<'a, S> From<&'a HttpRequest<S>> for HttpResponseBuilder
sourcefn from(req: &'a HttpRequest<S>) -> HttpResponseBuilder
fn from(req: &'a HttpRequest<S>) -> HttpResponseBuilder
sourceimpl<S> FromRequest<S> for HttpRequest<S>
impl<S> FromRequest<S> for HttpRequest<S>
type Result = HttpRequest<S>
type Result = HttpRequest<S>
sourcefn from_request(req: &HttpRequest<S>, _: &Self::Config) -> Self::Result
fn from_request(req: &HttpRequest<S>, _: &Self::Config) -> Self::Result
sourcefn extract(req: &HttpRequest<S>) -> Self::Result
fn extract(req: &HttpRequest<S>) -> Self::Result
sourceimpl<S> HttpMessage for HttpRequest<S>
impl<S> HttpMessage for HttpRequest<S>
sourcefn content_type(&self) -> &str
fn content_type(&self) -> &str
sourcefn encoding(&self) -> Result<EncodingRef, ContentTypeError>
fn encoding(&self) -> Result<EncodingRef, ContentTypeError>
sourcefn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>
sourcefn chunked(&self) -> Result<bool, ParseError>
fn chunked(&self) -> Result<bool, ParseError>
sourcefn body(&self) -> MessageBody<Self>
fn body(&self) -> MessageBody<Self>
sourcefn urlencoded<T: DeserializeOwned>(&self) -> UrlEncoded<Self, T>
fn urlencoded<T: DeserializeOwned>(&self) -> UrlEncoded<Self, T>
application/x-www-form-urlencoded
encoded request’s body.
Return UrlEncoded
future. Form can be deserialized to any type that
implements Deserialize
trait from serde. Read more