# actix_web::HttpRequest - Rust
API documentation for the Rust `HttpRequest` struct in crate `actix_web`.
Keywords: rust, rustlang, rust-lang, HttpRequest

# Struct actix_web::HttpRequest [−] [src]

    pub struct HttpRequest<S = ()> { /* fields omitted */ }

An HTTP Request

## Methods

###

`impl<S> HttpRequest<S>`

[src]

####
ⓘImportant traits for &'a mut R

### Important traits for &'a mut R

`impl<'a, R> Read for &'a mut R where
R: Read + ?Sized, impl<'a, W> Write for &'a mut W where
W: Write + ?Sized, impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;`

`pub fn state(&self) -> &S`

[src]

Shared application state

####

`pub fn request(&self) -> &Request`

[src]

Server request

####

`pub fn extensions(&self) -> Ref<Extensions>`

[src]

Request extensions

####

`pub fn extensions_mut(&self) -> RefMut<Extensions>`

[src]

Mutable reference to a the request's extensions

####

`pub fn response(&self, status: StatusCode, body: Body) -> HttpResponse`

[src]

Create http response

####

`pub fn build_response(&self, status: StatusCode) -> HttpResponseBuilder`

[src]

Create http response builder

####

`pub fn uri(&self) -> &Uri`

[src]

Read the Request Uri.

####

`pub fn method(&self) -> &Method`

[src]

Read the Request method.

####

`pub fn version(&self) -> Version`

[src]

Read the Request Version.

####

`pub fn path(&self) -> &str`

[src]

The target path of this Request.

####

`pub fn connection_info(&self) -> Ref<ConnectionInfo>`

[src]

Get ConnectionInfo for the correct request.

####

`pub fn url_for<U, I>( &self, name: &str, elements: U ) -> Result<Url, UrlGenerationError> where U: IntoIterator<Item = I>, I: AsRef<str>,`

[src]

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();
    }

####

`pub fn url_for_static(&self, name: &str) -> Result<Url, UrlGenerationError>`

[src]

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.

####

`pub fn resource(&self) -> &ResourceInfo`

[src]

This method returns reference to current `RouteInfo` object.

####

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

[src]

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.

####

`pub fn query(&self) -> Ref<HashMap<String, String>>`

[src]

url query parameters.

####

`pub fn query_string(&self) -> &str`

[src]

The query string in the URL.

E.g., id=10

####

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

[src]

Load request cookies.

####

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

[src]

Return request cookie.

####

`pub fn match_info(&self) -> &Params`

[src]

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.

####

`pub fn set_read_buffer_capacity(&mut self, cap: usize)`

[src]

Set read buffer capacity

Default buffer capacity is 32Kb.

## Methods from Deref<Target = Request>

####

`pub fn uri(&self) -> &Uri`

[src]

Read the Request Uri.

####

`pub fn method(&self) -> &Method`

[src]

Read the Request method.

####

`pub fn version(&self) -> Version`

[src]

Read the Request Version.

####

`pub fn path(&self) -> &str`

[src]

The target path of this Request.

####

`pub fn headers(&self) -> &HeaderMap`

[src]

Returns Request's headers.

####

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

[src]

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.

####

`pub fn keep_alive(&self) -> bool`

[src]

Checks if a connection should be kept alive.

####

`pub fn extensions(&self) -> Ref<Extensions>`

[src]

Request extensions

####

`pub fn extensions_mut(&self) -> RefMut<Extensions>`

[src]

Mutable reference to a the request's extensions

####

`pub fn upgrade(&self) -> bool`

[src]

Check if request requires connection upgrade

####

`pub fn connection_info(&self) -> Ref<ConnectionInfo>`

[src]

Get ConnectionInfo for the correct request.

####

`pub fn server_settings(&self) -> &ServerSettings`

[src]

Server settings

## Trait Implementations

###

`impl<S> HttpMessage for HttpRequest<S>`

[src]

#### `type Stream = Payload`

Type of message payload stream

####

`fn headers(&self) -> &HeaderMap`

[src]

Read the message headers.

####

`fn payload(&self) -> Payload`

[src]

Message payload stream

####

`fn content_type(&self) -> &str`

[src]

Read the request content type. If request does not contain Content-Type header, empty str get returned. Read more

####

`fn encoding(&self) -> Result<EncodingRef, ContentTypeError>`

[src]

Get content type encoding Read more

####

`fn mime_type(&self) -> Result<Option<Mime>, ContentTypeError>`

[src]

Convert the request content type to a known mime type.

####

`fn chunked(&self) -> Result<bool, ParseError>`

[src]

Check if request has chunked transfer encoding

####

`fn body(&self) -> MessageBody<Self>`

[src]

Load http message body. Read more

####

`fn urlencoded<T: DeserializeOwned>(&self) -> UrlEncoded<Self, T>`

[src]

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

####

`fn json<T: DeserializeOwned>(&self) -> JsonBody<Self, T>`

[src]

Parse `application/json` encoded body. Return `JsonBody<T>` future. It resolves to a `T` value. Read more

####

`fn multipart(&self) -> Multipart<Self::Stream>`

[src]

Return stream to http payload processes as multipart. Read more

####

`fn readlines(&self) -> Readlines<Self>`

[src]

Return stream of lines.

###

`impl<S> Deref for HttpRequest<S>`

[src]

#### `type Target = Request`

The resulting type after dereferencing.

####

`fn deref(&self) -> &Request`

[src]

Dereferences the value.

###

`impl<S> Drop for HttpRequest<S>`

[src]

####

`fn drop(&mut self)`

[src]

Executes the destructor for this type. Read more

###

`impl<S> Clone for HttpRequest<S>`

[src]

####

`fn clone(&self) -> HttpRequest<S>`

[src]

Returns a copy of the value. Read more

####

`fn clone_from(&mut self, source: &Self)`

1.0.0
[src]

Performs copy-assignment from `source`. Read more

###

`impl<S> FromRequest<S> for HttpRequest<S>`

[src]

#### `type Config = ()`

Configuration for conversion process

#### `type Result = Self`

Future that resolves to a Self

####

`fn from_request(req: &HttpRequest<S>, _: &Self::Config) -> Self::Result`

[src]

Convert request to a Self

####

`fn extract(req: &HttpRequest<S>) -> Self::Result`

[src]

Convert request to a Self Read more

###

`impl<S> Debug for HttpRequest<S>`

[src]

####

`fn fmt(&self, f: &mut Formatter) -> Result`

[src]

Formats the value using the given formatter. Read more

###

`impl<'a, S> From<&'a HttpRequest<S>> for HttpResponseBuilder`

[src]

####

`fn from(req: &'a HttpRequest<S>) -> HttpResponseBuilder`

[src]

Performs the conversion.

###

`impl<'a, S: 'static> From<&'a HttpRequest<S>> for ClientRequestBuilder`

[src]

Create `ClientRequestBuilder` from `HttpRequest`

It is useful for proxy requests. This implementation copies all request headers and the method.

####

`fn from(req: &'a HttpRequest<S>) -> ClientRequestBuilder`

[src]

Performs the conversion.

###

`impl<S> RequestIdentity for HttpRequest<S>`

[src]

####

`fn identity(&self) -> Option<String>`

[src]

Return the claimed identity of the user associated request or `None` if no identity can be found associated with the request. Read more

####

`fn remember(&self, identity: String)`

[src]

Remember identity.

####

`fn forget(&self)`

[src]

This method is used to 'forget' the current identity on subsequent requests. Read more

###

`impl<S> RequestSession for HttpRequest<S>`

[src]

####

`fn session(&self) -> Session`

[src]

Get the session from the request

## Auto Trait Implementations

###

`impl<S = ()> !Send for HttpRequest<S>`

###

`impl<S = ()> !Sync for HttpRequest<S>`

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)