Struct actix_web::web::HttpRequest [−][src]
pub struct HttpRequest(_);
Expand description
An HTTP Request
Implementations
This method returns reference to the request head
The query string in the URL.
E.g., id=10
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.
The resource definition pattern that matched the path. Useful for logging and metrics.
For example, when a resource with pattern /user/{id}/profile
is defined and a call is made
to /user/123/profile
this function would return Some("/user/{id}/profile")
.
Returns a None when no resource is fully matched, including default services.
The resource name that matched the path. Useful for logging and metrics.
Returns a None when no resource is fully matched, including default services.
Request extensions
Mutable reference to a the request’s extensions
pub 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()
.service(web::resource("/test/{one}/{two}/{three}")
.name("foo") // <- set resource name, then it could be used in `url_for`
.route(web::get().to(|| HttpResponse::Ok()))
);
}
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.
Get a reference to a ResourceMap
of current application.
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()
should be used.
Get ConnectionInfo for the current request.
This method panics if request’s extensions container is already borrowed.
App config
Trait Implementations
It is possible to get HttpRequest
as an extractor handler parameter
Example
use actix_web::{web, App, HttpRequest};
use serde_derive::Deserialize;
/// extract `Thing` from request
async fn index(req: HttpRequest) -> String {
format!("Got thing: {:?}", req)
}
fn main() {
let app = App::new().service(
web::resource("/users/{first}").route(
web::get().to(index))
);
}
Convert request to a Self
Convert request to a Self Read more
Request extensions
Mutable reference to a the request’s extensions
Message payload stream
Read the request content type. If request does not contain Content-Type header, empty str get returned. Read more
Get content type encoding Read more
Convert the request content type to a known mime type.
Check if request has chunked transfer encoding
Load request cookies.
Return request cookie.
Auto Trait Implementations
impl !RefUnwindSafe for HttpRequest
impl !Send for HttpRequest
impl !Sync for HttpRequest
impl Unpin for HttpRequest
impl !UnwindSafe for HttpRequest
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more