Struct actix_web::HttpRequest
[−]
[src]
pub struct HttpRequest<S = ()>(_, _, _);
An HTTP Request
Methods
impl HttpRequest<()>
[src]
fn new(
method: Method,
uri: Uri,
version: Version,
headers: HeaderMap,
payload: Option<Payload>
) -> HttpRequest
[src]
method: Method,
uri: Uri,
version: Version,
headers: HeaderMap,
payload: Option<Payload>
) -> HttpRequest
Construct a new Request.
fn with_state<S>(self, state: Rc<S>, router: Router) -> HttpRequest<S>
[src]
Construct new http request with state.
impl<S> HttpRequest<S>
[src]
fn change_state<NS>(&self, state: Rc<NS>) -> HttpRequest<NS>
[src]
Construct new http request with state.
fn state(&self) -> &S
[src]
Shared application state
fn extensions(&mut self) -> &mut Extensions
[src]
Protocol extensions.
fn uri(&self) -> &Uri
[src]
Read the Request Uri.
fn method(&self) -> &Method
[src]
Read the Request method.
fn version(&self) -> Version
[src]
Read the Request Version.
fn headers(&self) -> &HeaderMap
[src]
Read the Request Headers.
fn path(&self) -> &str
[src]
The target path of this Request.
fn connection_info(&self) -> &ConnectionInfo
[src]
Get ConnectionInfo for currect request.
fn url_for<U, I>(
&self,
name: &str,
elements: U
) -> Result<Url, UrlGenerationError> where
U: IntoIterator<Item = I>,
I: AsRef<str>,
[src]
&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 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(); }
fn router(&self) -> Option<&Router>
[src]
This method returns reference to current Router
object.
fn peer_addr(&self) -> Option<&SocketAddr>
[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.
fn query(&self) -> &Params
[src]
Get a reference to the Params object. Params is a container for url query parameters.
fn query_string(&self) -> &str
[src]
The query string in the URL.
E.g., id=10
[src]
Load request cookies.
[src]
Return request cookie.
fn match_info(&self) -> &Params
[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.
fn keep_alive(&self) -> bool
[src]
Checks if a connection should be kept alive.
fn content_type(&self) -> &str
[src]
Read the request content type. If request does not contain Content-Type header, empty str get returned.
fn chunked(&self) -> Result<bool, ParseError>
[src]
Check if request has chunked transfer encoding
fn range(&self, size: u64) -> Result<Vec<HttpRange>, HttpRangeError>
[src]
Parses Range HTTP header string as per RFC 2616.
size
is full size of response (file).
fn payload(&self) -> &Payload
[src]
Returns reference to the associated http payload.
fn payload_mut(&mut self) -> &mut Payload
[src]
Returns mutable reference to the associated http payload.
fn body(&self) -> RequestBody
[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() }
fn multipart(&mut self) -> Multipart
[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() }
fn urlencoded(&self) -> UrlEncoded
[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() }
fn json<T: DeserializeOwned>(&self) -> JsonBody<S, T>
[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]
fn default() -> HttpRequest
[src]
Construct default request
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