2018-04-07 17:10:36 +02:00
|
|
|
//! Actix web is a small, pragmatic, and extremely fast web framework
|
|
|
|
//! for Rust.
|
2017-12-13 23:35:21 -08:00
|
|
|
//!
|
2018-01-09 10:08:06 -08:00
|
|
|
//! ```rust
|
2018-06-02 16:03:23 -07:00
|
|
|
//! use actix_web::{server, App, Path, Responder};
|
2018-01-09 10:08:06 -08:00
|
|
|
//! # use std::thread;
|
2017-12-13 23:35:21 -08:00
|
|
|
//!
|
2018-06-02 16:03:23 -07:00
|
|
|
//! fn index(info: Path<(String, u32)>) -> impl Responder {
|
2018-06-01 09:36:16 -07:00
|
|
|
//! format!("Hello {}! id:{}", info.0, info.1)
|
2017-12-13 23:35:21 -08:00
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! fn main() {
|
2018-06-01 10:27:23 -07:00
|
|
|
//! # thread::spawn(|| {
|
2018-06-01 09:36:16 -07:00
|
|
|
//! server::new(|| {
|
|
|
|
//! App::new().resource("/{name}/{id}/index.html", |r| r.with(index))
|
|
|
|
//! }).bind("127.0.0.1:8080")
|
|
|
|
//! .unwrap()
|
2018-01-09 10:08:06 -08:00
|
|
|
//! .run();
|
2018-06-01 10:27:23 -07:00
|
|
|
//! # });
|
2017-12-13 23:35:21 -08:00
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
2018-04-07 17:27:53 +02:00
|
|
|
//! ## Documentation & community resources
|
|
|
|
//!
|
|
|
|
//! Besides the API documentation (which you are currently looking
|
|
|
|
//! at!), several other resources are available:
|
2017-12-13 23:35:21 -08:00
|
|
|
//!
|
2018-05-23 11:20:12 -07:00
|
|
|
//! * [User Guide](https://actix.rs/docs/)
|
2018-01-11 18:49:30 -08:00
|
|
|
//! * [Chat on gitter](https://gitter.im/actix/actix)
|
2018-01-11 18:47:34 -08:00
|
|
|
//! * [GitHub repository](https://github.com/actix/actix-web)
|
2018-02-18 22:23:17 -08:00
|
|
|
//! * [Cargo package](https://crates.io/crates/actix-web)
|
2018-04-07 17:27:53 +02:00
|
|
|
//!
|
|
|
|
//! To get started navigating the API documentation you may want to
|
|
|
|
//! consider looking at the following pages:
|
|
|
|
//!
|
|
|
|
//! * [App](struct.App.html): This struct represents an actix-web
|
|
|
|
//! application and is used to configure routes and other common
|
|
|
|
//! settings.
|
|
|
|
//!
|
|
|
|
//! * [HttpServer](server/struct.HttpServer.html): This struct
|
|
|
|
//! represents an HTTP server instance and is used to instantiate and
|
|
|
|
//! configure servers.
|
|
|
|
//!
|
|
|
|
//! * [HttpRequest](struct.HttpRequest.html) and
|
|
|
|
//! [HttpResponse](struct.HttpResponse.html): These structs
|
|
|
|
//! represent HTTP requests and responses and expose various methods
|
2018-05-06 19:07:30 +03:00
|
|
|
//! for inspecting, creating and otherwise utilizing them.
|
2017-12-13 23:35:21 -08:00
|
|
|
//!
|
|
|
|
//! ## Features
|
|
|
|
//!
|
|
|
|
//! * Supported *HTTP/1.x* and *HTTP/2.0* protocols
|
|
|
|
//! * Streaming and pipelining
|
|
|
|
//! * Keep-alive and slow requests handling
|
2018-02-26 14:33:56 -08:00
|
|
|
//! * `WebSockets` server/client
|
2017-12-13 23:35:21 -08:00
|
|
|
//! * Transparent content compression/decompression (br, gzip, deflate)
|
|
|
|
//! * Configurable request routing
|
2018-02-28 22:31:54 -08:00
|
|
|
//! * Graceful server shutdown
|
2017-12-13 23:35:21 -08:00
|
|
|
//! * Multipart streams
|
2018-04-07 17:10:36 +02:00
|
|
|
//! * SSL support with OpenSSL or `native-tls`
|
2018-03-07 21:39:20 -08:00
|
|
|
//! * Middlewares (`Logger`, `Session`, `CORS`, `CSRF`, `DefaultHeaders`)
|
2018-04-07 17:10:36 +02:00
|
|
|
//! * Built on top of [Actix actor framework](https://github.com/actix/actix)
|
2018-05-24 21:09:20 -07:00
|
|
|
//! * Supported Rust version: 1.26 or later
|
2018-05-15 10:20:32 -07:00
|
|
|
//!
|
|
|
|
//! ## Package feature
|
|
|
|
//!
|
|
|
|
//! * `tls` - enables ssl support via `native-tls` crate
|
2018-09-08 14:55:39 -07:00
|
|
|
//! * `ssl` - enables ssl support via `openssl` crate, supports `http/2`
|
|
|
|
//! * `rust-tls` - enables ssl support via `rustls` crate, supports `http/2`
|
2018-08-17 17:04:16 +01:00
|
|
|
//! * `uds` - enables support for making client requests via Unix Domain Sockets.
|
|
|
|
//! Unix only. Not necessary for *serving* requests.
|
2018-05-15 10:20:32 -07:00
|
|
|
//! * `session` - enables session support, includes `ring` crate as
|
|
|
|
//! dependency
|
|
|
|
//! * `brotli` - enables `brotli` compression support, requires `c`
|
|
|
|
//! compiler
|
2018-07-25 20:22:18 +03:00
|
|
|
//! * `flate2-c` - enables `gzip`, `deflate` compression support, requires
|
2018-05-15 10:20:32 -07:00
|
|
|
//! `c` compiler
|
2018-07-25 20:22:18 +03:00
|
|
|
//! * `flate2-rust` - experimental rust based implementation for
|
2018-05-15 10:20:32 -07:00
|
|
|
//! `gzip`, `deflate` compression.
|
|
|
|
//!
|
2017-11-24 10:28:43 -08:00
|
|
|
#![cfg_attr(actix_nightly, feature(
|
2017-11-24 10:03:13 -08:00
|
|
|
specialization, // for impl ErrorResponse for std::error::Error
|
2018-06-11 12:21:09 -07:00
|
|
|
extern_prelude,
|
2018-10-01 21:16:56 -07:00
|
|
|
tool_lints,
|
2017-11-24 10:03:13 -08:00
|
|
|
))]
|
2018-06-02 15:50:45 +02:00
|
|
|
#![warn(missing_docs)]
|
2017-11-24 10:03:13 -08:00
|
|
|
|
2017-10-06 21:48:14 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2018-01-27 22:03:03 -08:00
|
|
|
extern crate base64;
|
2018-02-09 17:20:28 -08:00
|
|
|
extern crate byteorder;
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate bytes;
|
2017-10-16 19:21:24 -07:00
|
|
|
extern crate regex;
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate sha1;
|
|
|
|
extern crate time;
|
2017-10-06 21:48:14 -07:00
|
|
|
#[macro_use]
|
2017-12-07 21:52:46 -08:00
|
|
|
extern crate bitflags;
|
|
|
|
#[macro_use]
|
2017-12-29 01:01:31 -08:00
|
|
|
extern crate failure;
|
|
|
|
#[macro_use]
|
2018-04-01 17:37:22 -07:00
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
2017-10-06 21:48:14 -07:00
|
|
|
extern crate futures;
|
2017-10-14 22:52:38 -07:00
|
|
|
extern crate cookie;
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate futures_cpupool;
|
2018-06-30 20:01:48 +08:00
|
|
|
extern crate htmlescape;
|
2018-03-30 17:31:18 -07:00
|
|
|
extern crate http as modhttp;
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate httparse;
|
|
|
|
extern crate language_tags;
|
2018-07-06 22:28:08 +01:00
|
|
|
extern crate lazycell;
|
2017-10-18 23:43:50 -07:00
|
|
|
extern crate mime;
|
2017-10-16 01:19:23 -07:00
|
|
|
extern crate mime_guess;
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate mio;
|
|
|
|
extern crate net2;
|
2018-06-18 04:56:18 +06:00
|
|
|
extern crate parking_lot;
|
2018-01-27 22:03:03 -08:00
|
|
|
extern crate rand;
|
2018-04-30 19:51:55 -07:00
|
|
|
extern crate slab;
|
2018-05-24 21:03:16 -07:00
|
|
|
extern crate tokio;
|
2018-09-07 20:46:43 -07:00
|
|
|
extern crate tokio_current_thread;
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate tokio_io;
|
2018-05-24 21:03:16 -07:00
|
|
|
extern crate tokio_reactor;
|
|
|
|
extern crate tokio_tcp;
|
|
|
|
extern crate tokio_timer;
|
2018-08-17 17:04:16 +01:00
|
|
|
#[cfg(all(unix, feature = "uds"))]
|
|
|
|
extern crate tokio_uds;
|
2017-10-14 22:52:38 -07:00
|
|
|
extern crate url;
|
2018-04-13 16:02:01 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde;
|
|
|
|
#[cfg(feature = "brotli")]
|
2017-11-06 01:24:49 -08:00
|
|
|
extern crate brotli2;
|
2018-02-27 11:31:54 -08:00
|
|
|
extern crate encoding;
|
2018-04-24 12:24:04 -07:00
|
|
|
#[cfg(feature = "flate2")]
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate flate2;
|
|
|
|
extern crate h2 as http2;
|
|
|
|
extern crate num_cpus;
|
2018-08-23 09:48:01 -07:00
|
|
|
extern crate serde_urlencoded;
|
2018-06-06 14:06:01 +00:00
|
|
|
#[macro_use]
|
2017-10-27 22:19:00 -07:00
|
|
|
extern crate percent_encoding;
|
2018-04-13 16:02:01 -07:00
|
|
|
extern crate serde_json;
|
2017-12-07 16:22:26 -08:00
|
|
|
extern crate smallvec;
|
2018-09-07 23:34:27 -07:00
|
|
|
|
|
|
|
extern crate actix_net;
|
2018-04-13 16:02:01 -07:00
|
|
|
#[macro_use]
|
2018-06-02 09:14:47 -07:00
|
|
|
extern crate actix as actix_inner;
|
2017-10-06 21:48:14 -07:00
|
|
|
|
2017-12-03 18:51:52 -08:00
|
|
|
#[cfg(test)]
|
2018-04-13 16:02:01 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
2017-11-15 20:06:28 -10:00
|
|
|
|
2018-04-13 16:02:01 -07:00
|
|
|
#[cfg(feature = "tls")]
|
2017-11-01 16:34:58 -07:00
|
|
|
extern crate native_tls;
|
2018-08-23 10:10:13 -07:00
|
|
|
#[cfg(feature = "tls")]
|
|
|
|
extern crate tokio_tls;
|
2017-11-01 16:34:58 -07:00
|
|
|
|
2018-04-13 16:02:01 -07:00
|
|
|
#[cfg(feature = "openssl")]
|
2017-11-04 12:33:14 -07:00
|
|
|
extern crate openssl;
|
2018-04-13 16:02:01 -07:00
|
|
|
#[cfg(feature = "openssl")]
|
2017-11-04 12:33:14 -07:00
|
|
|
extern crate tokio_openssl;
|
|
|
|
|
2018-07-29 09:43:04 +03:00
|
|
|
#[cfg(feature = "rust-tls")]
|
|
|
|
extern crate rustls;
|
|
|
|
#[cfg(feature = "rust-tls")]
|
|
|
|
extern crate tokio_rustls;
|
|
|
|
#[cfg(feature = "rust-tls")]
|
|
|
|
extern crate webpki;
|
|
|
|
#[cfg(feature = "rust-tls")]
|
|
|
|
extern crate webpki_roots;
|
|
|
|
|
2017-10-06 21:48:14 -07:00
|
|
|
mod application;
|
2017-10-23 23:25:32 -07:00
|
|
|
mod body;
|
2017-10-06 21:48:14 -07:00
|
|
|
mod context;
|
2018-03-29 13:12:28 -07:00
|
|
|
mod de;
|
2018-06-17 03:22:08 +06:00
|
|
|
mod extensions;
|
2018-04-02 14:55:42 -07:00
|
|
|
mod extractor;
|
2018-02-26 15:26:27 -08:00
|
|
|
mod handler;
|
2018-03-30 17:31:18 -07:00
|
|
|
mod header;
|
|
|
|
mod helpers;
|
2018-04-29 21:05:10 -07:00
|
|
|
mod httpcodes;
|
2018-02-27 15:03:28 -08:00
|
|
|
mod httpmessage;
|
2017-10-14 22:52:38 -07:00
|
|
|
mod httprequest;
|
2017-10-15 09:33:17 -07:00
|
|
|
mod httpresponse;
|
2017-12-05 17:09:15 -08:00
|
|
|
mod info;
|
2017-12-20 17:51:28 -08:00
|
|
|
mod json;
|
2018-02-26 15:26:27 -08:00
|
|
|
mod param;
|
|
|
|
mod payload;
|
2017-11-24 22:15:52 -08:00
|
|
|
mod pipeline;
|
2018-04-13 16:02:01 -07:00
|
|
|
mod resource;
|
|
|
|
mod route;
|
|
|
|
mod router;
|
2018-04-29 19:35:50 -07:00
|
|
|
mod scope;
|
2018-04-17 12:55:13 -07:00
|
|
|
mod uri;
|
2018-03-26 23:10:31 -07:00
|
|
|
mod with;
|
2017-10-07 21:48:00 -07:00
|
|
|
|
2018-01-29 11:39:26 -08:00
|
|
|
pub mod client;
|
2017-11-15 20:06:28 -10:00
|
|
|
pub mod error;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub mod fs;
|
2017-12-26 19:59:41 -08:00
|
|
|
pub mod middleware;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub mod multipart;
|
2017-12-04 13:32:05 -08:00
|
|
|
pub mod pred;
|
2018-01-11 18:35:05 -08:00
|
|
|
pub mod server;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub mod test;
|
|
|
|
pub mod ws;
|
2018-03-31 00:16:55 -07:00
|
|
|
pub use application::App;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub use body::{Binary, Body};
|
|
|
|
pub use context::HttpContext;
|
|
|
|
pub use error::{Error, ResponseError, Result};
|
2018-06-17 03:22:08 +06:00
|
|
|
pub use extensions::Extensions;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub use extractor::{Form, Path, Query};
|
2018-05-15 10:20:32 -07:00
|
|
|
pub use handler::{
|
|
|
|
AsyncResponder, Either, FromRequest, FutureResponse, Responder, State,
|
|
|
|
};
|
2018-04-02 14:55:42 -07:00
|
|
|
pub use httpmessage::HttpMessage;
|
2017-12-07 16:40:29 -08:00
|
|
|
pub use httprequest::HttpRequest;
|
2017-11-26 22:53:28 -08:00
|
|
|
pub use httpresponse::HttpResponse;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub use json::Json;
|
2018-04-29 19:35:50 -07:00
|
|
|
pub use scope::Scope;
|
2018-06-25 10:58:04 +06:00
|
|
|
pub use server::Request;
|
2018-05-09 05:48:06 -07:00
|
|
|
|
2018-05-31 20:43:14 +03:00
|
|
|
pub mod actix {
|
2018-06-02 09:14:47 -07:00
|
|
|
//! Re-exports [actix's](https://docs.rs/actix/) prelude
|
2018-05-31 20:43:14 +03:00
|
|
|
|
2018-06-02 09:14:47 -07:00
|
|
|
extern crate actix;
|
|
|
|
pub use self::actix::actors::resolver;
|
|
|
|
pub use self::actix::actors::signal;
|
|
|
|
pub use self::actix::fut;
|
|
|
|
pub use self::actix::msgs;
|
|
|
|
pub use self::actix::prelude::*;
|
2018-06-19 12:07:07 +06:00
|
|
|
pub use self::actix::{run, spawn};
|
2018-05-31 20:43:14 +03:00
|
|
|
}
|
|
|
|
|
2018-04-13 16:02:01 -07:00
|
|
|
#[cfg(feature = "openssl")]
|
2018-01-29 23:01:20 -08:00
|
|
|
pub(crate) const HAS_OPENSSL: bool = true;
|
2018-04-13 16:02:01 -07:00
|
|
|
#[cfg(not(feature = "openssl"))]
|
2018-01-29 23:01:20 -08:00
|
|
|
pub(crate) const HAS_OPENSSL: bool = false;
|
|
|
|
|
2018-04-13 16:02:01 -07:00
|
|
|
#[cfg(feature = "tls")]
|
2018-03-06 17:34:46 -08:00
|
|
|
pub(crate) const HAS_TLS: bool = true;
|
2018-04-13 16:02:01 -07:00
|
|
|
#[cfg(not(feature = "tls"))]
|
2018-03-06 17:34:46 -08:00
|
|
|
pub(crate) const HAS_TLS: bool = false;
|
2018-01-29 23:01:20 -08:00
|
|
|
|
2018-07-29 09:43:04 +03:00
|
|
|
#[cfg(feature = "rust-tls")]
|
|
|
|
pub(crate) const HAS_RUSTLS: bool = true;
|
|
|
|
#[cfg(not(feature = "rust-tls"))]
|
|
|
|
pub(crate) const HAS_RUSTLS: bool = false;
|
|
|
|
|
2017-12-06 17:06:40 -08:00
|
|
|
pub mod dev {
|
2018-04-13 16:02:01 -07:00
|
|
|
//! The `actix-web` prelude for library developers
|
|
|
|
//!
|
|
|
|
//! The purpose of this module is to alleviate imports of many common actix
|
|
|
|
//! traits by adding a glob import to the top of actix heavy modules:
|
|
|
|
//!
|
|
|
|
//! ```
|
|
|
|
//! # #![allow(unused_imports)]
|
|
|
|
//! use actix_web::dev::*;
|
|
|
|
//! ```
|
2017-12-06 17:06:40 -08:00
|
|
|
|
2017-12-13 22:36:28 -08:00
|
|
|
pub use body::BodyStream;
|
2018-02-28 11:10:54 -08:00
|
|
|
pub use context::Drain;
|
2018-04-04 21:13:48 -07:00
|
|
|
pub use extractor::{FormConfig, PayloadConfig};
|
2018-05-03 16:22:08 -07:00
|
|
|
pub use handler::{AsyncResult, Handler};
|
2018-08-16 16:11:15 +03:00
|
|
|
pub use httpmessage::{MessageBody, Readlines, UrlEncoded};
|
2017-12-06 17:06:40 -08:00
|
|
|
pub use httpresponse::HttpResponseBuilder;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub use info::ConnectionInfo;
|
|
|
|
pub use json::{JsonBody, JsonConfig};
|
|
|
|
pub use param::{FromParam, Params};
|
2018-07-18 10:01:28 +06:00
|
|
|
pub use payload::{Payload, PayloadBuffer};
|
2018-08-23 09:48:01 -07:00
|
|
|
pub use pipeline::Pipeline;
|
2018-07-12 15:30:01 +06:00
|
|
|
pub use resource::Resource;
|
2018-04-13 16:02:01 -07:00
|
|
|
pub use route::Route;
|
2018-07-15 15:24:27 +06:00
|
|
|
pub use router::{ResourceDef, ResourceInfo, ResourceType, Router};
|
2017-12-06 17:06:40 -08:00
|
|
|
}
|
2018-03-30 17:31:18 -07:00
|
|
|
|
|
|
|
pub mod http {
|
2018-04-07 17:10:36 +02:00
|
|
|
//! Various HTTP related types
|
2018-03-30 17:31:18 -07:00
|
|
|
|
|
|
|
// re-exports
|
|
|
|
pub use modhttp::{Method, StatusCode, Version};
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2018-04-13 16:02:01 -07:00
|
|
|
pub use modhttp::{uri, Error, Extensions, HeaderMap, HttpTryFrom, Uri};
|
2018-03-30 17:31:18 -07:00
|
|
|
|
|
|
|
pub use cookie::{Cookie, CookieBuilder};
|
|
|
|
|
|
|
|
pub use helpers::NormalizePath;
|
|
|
|
|
2018-06-02 15:51:58 +02:00
|
|
|
/// Various http headers
|
2018-03-30 17:31:18 -07:00
|
|
|
pub mod header {
|
2018-04-13 16:02:01 -07:00
|
|
|
pub use header::*;
|
2018-08-23 09:48:01 -07:00
|
|
|
pub use header::{
|
|
|
|
Charset, ContentDisposition, DispositionParam, DispositionType, LanguageTag,
|
|
|
|
};
|
2018-03-30 17:31:18 -07:00
|
|
|
}
|
|
|
|
pub use header::ContentEncoding;
|
|
|
|
pub use httpresponse::ConnectionType;
|
|
|
|
}
|