Struct actix_web::HttpRequest

source ·
pub struct HttpRequest<S = ()> { /* private fields */ }
Expand description

An HTTP Request

Implementations

Construct new http request with empty state.

Shared application state

Server request

Request extensions

Mutable reference to a the request’s extensions

Create http response

Create http response builder

Read the Request Uri.

Read the Request method.

Read the Request Version.

The target path of this Request.

Get ConnectionInfo for the correct request.

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

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.

This method returns reference to current ResourceInfo object.

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.

url query parameters.

The query string in the URL.

E.g., id=10

Load request cookies.

Return request cookie.

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.

Set read buffer capacity

Default buffer capacity is 32Kb.

Methods from Deref<Target = Request>

Read the Request Uri.

Read the Request method.

Read the Request Version.

The target path of this Request.

Returns Request’s headers.

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.

Checks if a connection should be kept alive.

Request extensions

Mutable reference to a the request’s extensions

Check if request requires connection upgrade

Get ConnectionInfo for the correct request.

Io stream extensions

Server settings

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Executes the destructor for this type. Read more

Create ClientRequestBuilder from HttpRequest

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

Converts to this type from the input type.
Converts to this type from the input type.
Configuration for conversion process
Future that resolves to a Self
Convert request to a Self
Convert request to a Self Read more
Type of message payload stream
Read the message headers.
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 http message body. Read more
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
Parse application/json encoded body. Return JsonBody<T> future. It resolves to a T value. Read more
Return stream to http payload processes as multipart. Read more
Return stream of lines.
Return the claimed identity of the user associated request or None if no identity can be found associated with the request. Read more
Remember identity.
This method is used to ‘forget’ the current identity on subsequent requests. Read more
Get the session from the request

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.