2018-02-27 21:49:11 +01:00
|
|
|
//! Actix web is a small, pragmatic, extremely fast, web framework for Rust.
|
2017-12-14 08:35:21 +01:00
|
|
|
//!
|
2018-01-09 19:08:06 +01:00
|
|
|
//! ```rust
|
2018-03-30 00:07:12 +02:00
|
|
|
//! use actix_web::{Application, HttpServer, Path};
|
2018-01-09 19:08:06 +01:00
|
|
|
//! # use std::thread;
|
2017-12-14 08:35:21 +01:00
|
|
|
//!
|
2018-03-30 00:07:12 +02:00
|
|
|
//! fn index(info: Path<(String, u32)>) -> String {
|
|
|
|
//! format!("Hello {}! id:{}", info.0, info.1)
|
2017-12-14 08:35:21 +01:00
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! fn main() {
|
2018-01-09 19:08:06 +01:00
|
|
|
//! # thread::spawn(|| {
|
2017-12-14 08:35:21 +01:00
|
|
|
//! HttpServer::new(
|
|
|
|
//! || Application::new()
|
2018-03-30 00:07:12 +02:00
|
|
|
//! .resource("/{name}/{id}/index.html", |r| r.with(index)))
|
2018-01-09 19:08:06 +01:00
|
|
|
//! .bind("127.0.0.1:8080").unwrap()
|
|
|
|
//! .run();
|
|
|
|
//! # });
|
2017-12-14 08:35:21 +01:00
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! ## Documentation
|
|
|
|
//!
|
|
|
|
//! * [User Guide](http://actix.github.io/actix-web/guide/)
|
2018-01-12 03:49:30 +01:00
|
|
|
//! * [Chat on gitter](https://gitter.im/actix/actix)
|
2018-01-12 03:47:34 +01:00
|
|
|
//! * [GitHub repository](https://github.com/actix/actix-web)
|
2018-02-19 07:23:17 +01:00
|
|
|
//! * [Cargo package](https://crates.io/crates/actix-web)
|
|
|
|
//! * Supported Rust version: 1.21 or later
|
2017-12-14 08:35:21 +01:00
|
|
|
//!
|
|
|
|
//! ## Features
|
|
|
|
//!
|
|
|
|
//! * Supported *HTTP/1.x* and *HTTP/2.0* protocols
|
|
|
|
//! * Streaming and pipelining
|
|
|
|
//! * Keep-alive and slow requests handling
|
2018-02-26 23:33:56 +01:00
|
|
|
//! * `WebSockets` server/client
|
2017-12-14 08:35:21 +01:00
|
|
|
//! * Transparent content compression/decompression (br, gzip, deflate)
|
|
|
|
//! * Configurable request routing
|
2018-03-01 07:31:54 +01:00
|
|
|
//! * Graceful server shutdown
|
2017-12-14 08:35:21 +01:00
|
|
|
//! * Multipart streams
|
2018-03-01 07:31:54 +01:00
|
|
|
//! * SSL support with openssl or native-tls
|
2018-03-08 06:39:20 +01:00
|
|
|
//! * Middlewares (`Logger`, `Session`, `CORS`, `CSRF`, `DefaultHeaders`)
|
2018-03-01 07:31:54 +01:00
|
|
|
//! * Built on top of [Actix actor framework](https://github.com/actix/actix).
|
2017-10-07 06:48:14 +02:00
|
|
|
|
2017-11-24 19:28:43 +01:00
|
|
|
#![cfg_attr(actix_nightly, feature(
|
2017-11-24 19:03:13 +01:00
|
|
|
specialization, // for impl ErrorResponse for std::error::Error
|
|
|
|
))]
|
2018-01-29 23:44:25 +01:00
|
|
|
#![cfg_attr(feature = "cargo-clippy", allow(
|
2018-02-26 22:58:23 +01:00
|
|
|
decimal_literal_representation,suspicious_arithmetic_impl,))]
|
2017-11-24 19:03:13 +01:00
|
|
|
|
2017-10-07 06:48:14 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
extern crate time;
|
2018-01-28 07:03:03 +01:00
|
|
|
extern crate base64;
|
2017-10-07 06:48:14 +02:00
|
|
|
extern crate bytes;
|
2018-02-10 02:20:28 +01:00
|
|
|
extern crate byteorder;
|
2017-10-08 06:48:00 +02:00
|
|
|
extern crate sha1;
|
2017-10-17 04:21:24 +02:00
|
|
|
extern crate regex;
|
2017-10-07 06:48:14 +02:00
|
|
|
#[macro_use]
|
2017-12-08 06:52:46 +01:00
|
|
|
extern crate bitflags;
|
|
|
|
#[macro_use]
|
2017-12-29 10:01:31 +01:00
|
|
|
extern crate failure;
|
|
|
|
#[macro_use]
|
2017-10-07 06:48:14 +02:00
|
|
|
extern crate futures;
|
2018-03-07 23:56:53 +01:00
|
|
|
extern crate futures_cpupool;
|
2017-10-07 06:48:14 +02:00
|
|
|
extern crate tokio_io;
|
2017-10-29 14:05:31 +01:00
|
|
|
extern crate tokio_core;
|
2017-12-27 20:22:27 +01:00
|
|
|
extern crate mio;
|
|
|
|
extern crate net2;
|
2017-10-15 07:52:38 +02:00
|
|
|
extern crate cookie;
|
2018-03-31 02:31:18 +02:00
|
|
|
extern crate http as modhttp;
|
2017-10-07 06:48:14 +02:00
|
|
|
extern crate httparse;
|
2017-10-15 07:52:38 +02:00
|
|
|
extern crate http_range;
|
2017-10-19 08:43:50 +02:00
|
|
|
extern crate mime;
|
2017-10-16 10:19:23 +02:00
|
|
|
extern crate mime_guess;
|
2018-03-06 09:43:25 +01:00
|
|
|
extern crate language_tags;
|
2018-01-28 07:03:03 +01:00
|
|
|
extern crate rand;
|
2017-10-15 07:52:38 +02:00
|
|
|
extern crate url;
|
2017-11-10 22:26:12 +01:00
|
|
|
extern crate libc;
|
2018-03-29 23:30:45 +02:00
|
|
|
#[macro_use] extern crate serde;
|
2017-11-16 07:06:28 +01:00
|
|
|
extern crate serde_json;
|
2018-03-27 00:58:30 +02:00
|
|
|
extern crate serde_urlencoded;
|
2017-11-06 10:24:49 +01:00
|
|
|
extern crate flate2;
|
2018-03-14 01:21:22 +01:00
|
|
|
#[cfg(feature="brotli")]
|
2017-11-06 10:24:49 +01:00
|
|
|
extern crate brotli2;
|
2018-02-27 20:31:54 +01:00
|
|
|
extern crate encoding;
|
2017-10-28 07:19:00 +02:00
|
|
|
extern crate percent_encoding;
|
2017-12-08 01:22:26 +01:00
|
|
|
extern crate smallvec;
|
2017-12-13 02:21:00 +01:00
|
|
|
extern crate num_cpus;
|
2017-11-03 19:29:44 +01:00
|
|
|
extern crate h2 as http2;
|
2018-01-28 07:03:03 +01:00
|
|
|
extern crate trust_dns_resolver;
|
2017-12-27 21:58:32 +01:00
|
|
|
#[macro_use] extern crate actix;
|
2017-10-07 06:48:14 +02:00
|
|
|
|
2017-12-04 03:51:52 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use] extern crate serde_derive;
|
2017-11-16 07:06:28 +01:00
|
|
|
|
2017-11-02 00:34:58 +01:00
|
|
|
#[cfg(feature="tls")]
|
|
|
|
extern crate native_tls;
|
|
|
|
#[cfg(feature="tls")]
|
|
|
|
extern crate tokio_tls;
|
|
|
|
|
2017-11-04 20:33:14 +01:00
|
|
|
#[cfg(feature="openssl")]
|
|
|
|
extern crate openssl;
|
|
|
|
#[cfg(feature="openssl")]
|
|
|
|
extern crate tokio_openssl;
|
|
|
|
|
2017-10-07 06:48:14 +02:00
|
|
|
mod application;
|
2017-10-24 08:25:32 +02:00
|
|
|
mod body;
|
2017-10-07 06:48:14 +02:00
|
|
|
mod context;
|
2018-03-29 22:12:28 +02:00
|
|
|
mod de;
|
2018-02-27 00:26:27 +01:00
|
|
|
mod handler;
|
2018-03-31 02:31:18 +02:00
|
|
|
mod header;
|
|
|
|
mod helpers;
|
2018-02-28 00:03:28 +01:00
|
|
|
mod httpmessage;
|
2017-10-15 07:52:38 +02:00
|
|
|
mod httprequest;
|
2017-10-15 18:33:17 +02:00
|
|
|
mod httpresponse;
|
2017-12-06 02:09:15 +01:00
|
|
|
mod info;
|
2017-12-21 02:51:28 +01:00
|
|
|
mod json;
|
2017-12-05 01:09:22 +01:00
|
|
|
mod route;
|
2017-12-07 01:26:27 +01:00
|
|
|
mod router;
|
2017-10-07 06:48:14 +02:00
|
|
|
mod resource;
|
2018-02-27 00:26:27 +01:00
|
|
|
mod param;
|
|
|
|
mod payload;
|
2017-11-25 07:15:52 +01:00
|
|
|
mod pipeline;
|
2018-03-27 08:10:31 +02:00
|
|
|
mod with;
|
2017-10-08 06:48:00 +02:00
|
|
|
|
2018-01-29 20:39:26 +01:00
|
|
|
pub mod client;
|
2017-12-03 23:22:04 +01:00
|
|
|
pub mod fs;
|
2017-10-10 08:07:32 +02:00
|
|
|
pub mod ws;
|
2017-11-16 07:06:28 +01:00
|
|
|
pub mod error;
|
2017-10-07 06:48:14 +02:00
|
|
|
pub mod httpcodes;
|
2017-10-19 08:43:50 +02:00
|
|
|
pub mod multipart;
|
2017-12-27 04:59:41 +01:00
|
|
|
pub mod middleware;
|
2017-12-04 22:32:05 +01:00
|
|
|
pub mod pred;
|
2017-12-27 01:35:00 +01:00
|
|
|
pub mod test;
|
2018-01-12 03:35:05 +01:00
|
|
|
pub mod server;
|
2017-12-09 00:25:37 +01:00
|
|
|
pub use error::{Error, Result, ResponseError};
|
2017-11-10 22:42:32 +01:00
|
|
|
pub use body::{Body, Binary};
|
2018-01-12 03:35:05 +01:00
|
|
|
pub use json::Json;
|
2018-03-29 22:12:28 +02:00
|
|
|
pub use de::{Path, Query};
|
2017-11-27 07:53:28 +01:00
|
|
|
pub use application::Application;
|
2018-02-28 00:03:28 +01:00
|
|
|
pub use httpmessage::HttpMessage;
|
2017-12-08 01:40:29 +01:00
|
|
|
pub use httprequest::HttpRequest;
|
2017-11-27 07:53:28 +01:00
|
|
|
pub use httpresponse::HttpResponse;
|
2018-03-30 00:41:13 +02:00
|
|
|
pub use handler::{Either, Responder, AsyncResponder, FutureResponse, State};
|
2017-10-07 06:48:14 +02:00
|
|
|
pub use context::HttpContext;
|
2018-01-12 03:35:05 +01:00
|
|
|
pub use server::HttpServer;
|
2017-10-14 19:40:58 +02:00
|
|
|
|
2018-01-30 08:01:20 +01:00
|
|
|
#[cfg(feature="openssl")]
|
|
|
|
pub(crate) const HAS_OPENSSL: bool = true;
|
|
|
|
#[cfg(not(feature="openssl"))]
|
|
|
|
pub(crate) const HAS_OPENSSL: bool = false;
|
|
|
|
|
2018-03-07 02:34:46 +01:00
|
|
|
#[cfg(feature="tls")]
|
|
|
|
pub(crate) const HAS_TLS: bool = true;
|
|
|
|
#[cfg(not(feature="tls"))]
|
|
|
|
pub(crate) const HAS_TLS: bool = false;
|
2018-01-30 08:01:20 +01:00
|
|
|
|
2017-12-07 02:06:40 +01:00
|
|
|
pub mod dev {
|
|
|
|
//! 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-14 07:36:28 +01:00
|
|
|
pub use body::BodyStream;
|
2018-02-28 20:10:54 +01:00
|
|
|
pub use context::Drain;
|
2017-12-07 02:06:40 +01:00
|
|
|
pub use info::ConnectionInfo;
|
2018-03-29 22:12:28 +02:00
|
|
|
pub use handler::{Handler, Reply, FromRequest};
|
2018-03-29 19:44:26 +02:00
|
|
|
pub use route::Route;
|
|
|
|
pub use resource::Resource;
|
2018-03-28 23:24:32 +02:00
|
|
|
pub use with::WithHandler;
|
2017-12-21 05:30:54 +01:00
|
|
|
pub use json::JsonBody;
|
2017-12-08 01:22:26 +01:00
|
|
|
pub use router::{Router, Pattern};
|
|
|
|
pub use param::{FromParam, Params};
|
2018-03-29 06:58:08 +02:00
|
|
|
pub use httpmessage::{UrlEncoded, MessageBody};
|
2017-12-07 02:06:40 +01:00
|
|
|
pub use httpresponse::HttpResponseBuilder;
|
|
|
|
}
|
2018-03-31 02:31:18 +02:00
|
|
|
|
|
|
|
pub mod http {
|
|
|
|
//! Various http related types
|
|
|
|
|
|
|
|
// re-exports
|
|
|
|
pub use modhttp::{Method, StatusCode, Version};
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub use modhttp::{uri, Uri, Error, Extensions, HeaderMap, HttpTryFrom};
|
|
|
|
|
|
|
|
pub use http_range::HttpRange;
|
|
|
|
pub use cookie::{Cookie, CookieBuilder};
|
|
|
|
|
|
|
|
pub use helpers::NormalizePath;
|
|
|
|
|
|
|
|
pub mod header {
|
|
|
|
pub use ::header::*;
|
|
|
|
}
|
|
|
|
pub use header::ContentEncoding;
|
|
|
|
pub use httpresponse::ConnectionType;
|
|
|
|
}
|