Struct actix_web::HttpRequest [] [src]

pub struct HttpRequest<S = ()>(_, _, _);

An HTTP Request

Methods

impl HttpRequest<()>
[src]

[src]

Construct a new Request.

[src]

Construct new http request with state.

impl<S> HttpRequest<S>
[src]

[src]

Construct new http request with state.

[src]

Shared application state

[src]

Protocol extensions.

[src]

Read the Request Uri.

[src]

Read the Request method.

[src]

Read the Request Version.

[src]

Read the Request Headers.

[src]

The target path of this Request.

[src]

Get ConnectionInfo for currect request.

[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
    HTTPOk.into()
}

fn main() {
    let app = Application::new()
        .resource("/test/{one}/{two}/{three}", |r| {
             r.name("foo");  // <- set resource name, then it could be used in `url_for`
             r.method(Method::GET).f(|_| httpcodes::HTTPOk);
        })
        .finish();
}

[src]

This method returns reference to current Router object.

[src]

Peer socket address

Peer address is actuall 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.

[src]

Get a reference to the Params object. Params is a container for url query parameters.

[src]

The query string in the URL.

E.g., id=10

[src]

Load request cookies.

[src]

Return request cookie.

[src]

Get a reference to the Params object. Params is a container for url parameters. Route supports glob patterns: * for a single wildcard segment and :param for matching storing that segment of the request url in the Params object.

[src]

Checks if a connection should be kept alive.

[src]

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

[src]

Check if request has chunked transfer encoding

[src]

Parses Range HTTP header string as per RFC 2616. size is full size of response (file).

[src]

Returns reference to the associated http payload.

[src]

Returns mutable reference to the associated http payload.

[src]

Load request body.

By default only 256Kb payload reads to a memory, then BAD REQUEST http response get returns to a peer. Use RequestBody::limit() method to change upper limit.

use actix_web::*;
use bytes::Bytes;
use futures::future::Future;

fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
    req.body()                     // <- get Body future
       .limit(1024)                // <- change max size of the body to a 1kb
       .from_err()
       .and_then(|bytes: Bytes| {  // <- complete body
           println!("==== BODY ==== {:?}", bytes);
           Ok(httpcodes::HTTPOk.into())
       }).responder()
}

[src]

Return stream to http payload processes as multipart.

Content-type: multipart/form-data;

fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
    req.multipart().from_err()       // <- get multipart stream for current request
       .and_then(|item| match item { // <- iterate over multipart items
           multipart::MultipartItem::Field(field) => {
               // Field in turn is stream of *Bytes* object
               Either::A(field.from_err()
                         .map(|c| println!("-- CHUNK: \n{:?}", str::from_utf8(&c)))
                         .finish())
            },
            multipart::MultipartItem::Nested(mp) => {
                // Or item could be nested Multipart stream
                Either::B(ok(()))
            }
        })
        .finish()  // <- Stream::finish() combinator from actix
        .map(|_| httpcodes::HTTPOk.into())
        .responder()
}

[src]

Parse application/x-www-form-urlencoded encoded body. Return UrlEncoded future. It resolves to a HashMap<String, String> which contains decoded parameters.

Returns error:

  • content type is not application/x-www-form-urlencoded
  • transfer encoding is chunked.
  • content-length is greater than 256k
use actix_web::*;
use futures::future::{Future, ok};

fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
    req.urlencoded()         // <- get UrlEncoded future
       .from_err()
       .and_then(|params| {  // <- url encoded parameters
            println!("==== BODY ==== {:?}", params);
            ok(httpcodes::HTTPOk.into())
       })
       .responder()
}

[src]

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

Returns error:

  • content type is not application/json
  • content length is greater than 256k
use actix_web::*;
use futures::future::{Future, ok};

#[derive(Deserialize, Debug)]
struct MyObj {
    name: String,
}

fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
    req.json()                   // <- get JsonBody future
       .from_err()
       .and_then(|val: MyObj| {  // <- deserialized value
           println!("==== BODY ==== {:?}", val);
           Ok(httpcodes::HTTPOk.into())
       }).responder()
}

Trait Implementations

impl Default for HttpRequest<()>
[src]

[src]

Construct default request

impl<S> Clone for HttpRequest<S>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<S> Debug for HttpRequest<S>
[src]

[src]

Formats the value using the given formatter.

impl<S> RequestSession for HttpRequest<S>
[src]

[src]