From 3ee228005db54bbdd989c6fd2b03a366c984e485 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 31 Mar 2018 00:16:55 -0700 Subject: [PATCH] rename Application --- examples/basics/src/main.rs | 4 +- examples/diesel/src/main.rs | 4 +- examples/hello-world/src/main.rs | 4 +- examples/http-proxy/src/main.rs | 4 +- examples/json/src/main.rs | 8 +-- examples/juniper/src/main.rs | 8 +-- examples/multipart/src/main.rs | 4 +- examples/protobuf/src/main.rs | 4 +- examples/r2d2/src/main.rs | 5 +- examples/state/src/main.rs | 4 +- examples/template_tera/src/main.rs | 6 +- examples/tls/src/main.rs | 5 +- examples/unix-socket/src/main.rs | 9 +-- examples/web-cors/backend/src/main.rs | 4 +- examples/websocket-chat/src/main.rs | 6 +- examples/websocket/src/main.rs | 6 +- guide/src/qs_10.md | 14 ++--- guide/src/qs_12.md | 8 +-- guide/src/qs_13.md | 2 +- guide/src/qs_14.md | 2 +- guide/src/qs_2.md | 8 +-- guide/src/qs_3.md | 16 ++--- guide/src/qs_3_5.md | 22 +++---- guide/src/qs_4.md | 18 +++--- guide/src/qs_4_5.md | 10 +-- guide/src/qs_5.md | 54 ++++++++-------- guide/src/qs_7.md | 4 +- guide/src/qs_8.md | 6 +- guide/src/qs_9.md | 2 +- src/application.rs | 89 ++++++++++++++------------- src/de.rs | 12 ++-- src/fs.rs | 6 +- src/handler.rs | 12 ++-- src/helpers.rs | 12 ++-- src/httprequest.rs | 4 +- src/httpresponse.rs | 2 +- src/json.rs | 7 +-- src/lib.rs | 10 ++- src/middleware/cors.rs | 6 +- src/middleware/csrf.rs | 4 +- src/middleware/defaultheaders.rs | 4 +- src/middleware/logger.rs | 4 +- src/middleware/session.rs | 6 +- src/pred.rs | 4 +- src/resource.rs | 8 +-- src/route.rs | 10 +-- src/server/mod.rs | 4 +- src/server/srv.rs | 4 +- src/test.rs | 8 +-- src/ws/mod.rs | 2 +- tests/test_server.rs | 6 +- 51 files changed, 237 insertions(+), 238 deletions(-) diff --git a/examples/basics/src/main.rs b/examples/basics/src/main.rs index 7e1bc1c4f..750fc7640 100644 --- a/examples/basics/src/main.rs +++ b/examples/basics/src/main.rs @@ -9,7 +9,7 @@ use futures::Stream; use std::{io, env}; use actix_web::{error, fs, pred, - Application, HttpRequest, HttpResponse, HttpServer, Result, Error}; + App, HttpRequest, HttpResponse, HttpServer, Result, Error}; use actix_web::http::{Method, StatusCode}; use actix_web::middleware::{self, RequestSession}; use futures::future::{FutureResult, result}; @@ -100,7 +100,7 @@ fn main() { let sys = actix::System::new("basic-example"); let addr = HttpServer::new( - || Application::new() + || App::new() // enable logger .middleware(middleware::Logger::default()) // cookie session middleware diff --git a/examples/diesel/src/main.rs b/examples/diesel/src/main.rs index 76ba2d39f..cf5b183d1 100644 --- a/examples/diesel/src/main.rs +++ b/examples/diesel/src/main.rs @@ -18,7 +18,7 @@ extern crate env_logger; use actix::prelude::*; use actix_web::{http, middleware, - Application, HttpServer, HttpRequest, HttpResponse, Error, AsyncResponder}; + App, HttpServer, HttpRequest, HttpResponse, Error, AsyncResponder}; use diesel::prelude::*; use futures::future::Future; @@ -63,7 +63,7 @@ fn main() { // Start http server let _addr = HttpServer::new(move || { - Application::with_state(State{db: addr.clone()}) + App::with_state(State{db: addr.clone()}) // enable logger .middleware(middleware::Logger::default()) .resource("/{name}", |r| r.method(http::Method::GET).a(index))}) diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs index dc97c20e6..137be494e 100644 --- a/examples/hello-world/src/main.rs +++ b/examples/hello-world/src/main.rs @@ -2,7 +2,7 @@ extern crate actix; extern crate actix_web; extern crate env_logger; -use actix_web::{Application, HttpRequest, server, middleware}; +use actix_web::{App, HttpRequest, server, middleware}; fn index(_req: HttpRequest) -> &'static str { @@ -15,7 +15,7 @@ fn main() { let sys = actix::System::new("ws-example"); let _addr = server::new( - || Application::new() + || App::new() // enable logger .middleware(middleware::Logger::default()) .resource("/index.html", |r| r.f(|_| "Hello world!")) diff --git a/examples/http-proxy/src/main.rs b/examples/http-proxy/src/main.rs index 73c91c0af..a69fff88d 100644 --- a/examples/http-proxy/src/main.rs +++ b/examples/http-proxy/src/main.rs @@ -5,7 +5,7 @@ extern crate env_logger; use futures::{Future, Stream}; use actix_web::{client, server, middleware, - Application, AsyncResponder, Body, + App, AsyncResponder, Body, HttpRequest, HttpResponse, HttpMessage, Error}; /// Stream client request response and then send body to a server response @@ -45,7 +45,7 @@ fn main() { let sys = actix::System::new("http-proxy"); let _addr = server::new( - || Application::new() + || App::new() .middleware(middleware::Logger::default()) .resource("/streaming", |r| r.f(streaming)) .resource("/", |r| r.f(index))) diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index f92909fef..34730366e 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -7,9 +7,9 @@ extern crate serde_json; #[macro_use] extern crate serde_derive; #[macro_use] extern crate json; -use actix_web::{middleware, http, error, server, - Application, AsyncResponder, - HttpRequest, HttpResponse, HttpMessage, Error, Json}; +use actix_web::{ + middleware, http, error, server, + App, AsyncResponder, HttpRequest, HttpResponse, HttpMessage, Error, Json}; use bytes::BytesMut; use futures::{Future, Stream}; @@ -90,7 +90,7 @@ fn main() { let sys = actix::System::new("json-example"); let _ = server::new(|| { - Application::new() + App::new() // enable logger .middleware(middleware::Logger::default()) .resource("/extractor/{name}/{number}/", diff --git a/examples/juniper/src/main.rs b/examples/juniper/src/main.rs index a627425e1..26f63de95 100644 --- a/examples/juniper/src/main.rs +++ b/examples/juniper/src/main.rs @@ -13,9 +13,9 @@ extern crate actix_web; extern crate env_logger; use actix::prelude::*; -use actix_web::{middleware, http, server, - Application, AsyncResponder, - HttpRequest, HttpResponse, HttpMessage, Error}; +use actix_web::{ + middleware, http, server, + App, AsyncResponder, HttpRequest, HttpResponse, HttpMessage, Error}; use juniper::http::graphiql::graphiql_source; use juniper::http::GraphQLRequest; @@ -99,7 +99,7 @@ fn main() { // Start http server let _ = server::new(move || { - Application::with_state(State{executor: addr.clone()}) + App::with_state(State{executor: addr.clone()}) // enable logger .middleware(middleware::Logger::default()) .resource("/graphql", |r| r.method(http::Method::POST).h(graphql)) diff --git a/examples/multipart/src/main.rs b/examples/multipart/src/main.rs index 90a019467..cac76d30c 100644 --- a/examples/multipart/src/main.rs +++ b/examples/multipart/src/main.rs @@ -7,7 +7,7 @@ extern crate futures; use actix::*; use actix_web::{ http, middleware, multipart, server, - Application, AsyncResponder, HttpRequest, HttpResponse, HttpMessage, Error}; + App, AsyncResponder, HttpRequest, HttpResponse, HttpMessage, Error}; use futures::{Future, Stream}; use futures::future::{result, Either}; @@ -50,7 +50,7 @@ fn main() { let sys = actix::System::new("multipart-example"); let _ = server::new( - || Application::new() + || App::new() .middleware(middleware::Logger::default()) // <- logger .resource("/multipart", |r| r.method(http::Method::POST).a(index))) .bind("127.0.0.1:8080").unwrap() diff --git a/examples/protobuf/src/main.rs b/examples/protobuf/src/main.rs index 77ecf7bfb..ae61e0e46 100644 --- a/examples/protobuf/src/main.rs +++ b/examples/protobuf/src/main.rs @@ -12,7 +12,7 @@ extern crate prost_derive; use futures::Future; use actix_web::{ http, middleware, server, - Application, AsyncResponder, HttpRequest, HttpResponse, Error}; + App, AsyncResponder, HttpRequest, HttpResponse, Error}; mod protobuf; use protobuf::ProtoBufResponseBuilder; @@ -45,7 +45,7 @@ fn main() { let sys = actix::System::new("protobuf-example"); let _ = server::new(|| { - Application::new() + App::new() .middleware(middleware::Logger::default()) .resource("/", |r| r.method(http::Method::POST).f(index))}) .bind("127.0.0.1:8080").unwrap() diff --git a/examples/r2d2/src/main.rs b/examples/r2d2/src/main.rs index 528b4f200..a3cf637c7 100644 --- a/examples/r2d2/src/main.rs +++ b/examples/r2d2/src/main.rs @@ -12,8 +12,7 @@ extern crate rusqlite; use actix::prelude::*; use actix_web::{ - middleware, http, server, - Application, AsyncResponder, HttpRequest, HttpResponse, Error}; + middleware, http, server, App, AsyncResponder, HttpRequest, HttpResponse, Error}; use futures::future::Future; use r2d2_sqlite::SqliteConnectionManager; @@ -55,7 +54,7 @@ fn main() { // Start http server let _ = server::new(move || { - Application::with_state(State{db: addr.clone()}) + App::with_state(State{db: addr.clone()}) // enable logger .middleware(middleware::Logger::default()) .resource("/{name}", |r| r.method(http::Method::GET).a(index))}) diff --git a/examples/state/src/main.rs b/examples/state/src/main.rs index 7bd5f443a..e3b0890bd 100644 --- a/examples/state/src/main.rs +++ b/examples/state/src/main.rs @@ -11,7 +11,7 @@ use std::cell::Cell; use actix::prelude::*; use actix_web::{ - http, server, ws, middleware, Application, HttpRequest, HttpResponse}; + http, server, ws, middleware, App, HttpRequest, HttpResponse}; /// Application state struct AppState { @@ -59,7 +59,7 @@ fn main() { let sys = actix::System::new("ws-example"); let _ = server::new( - || Application::with_state(AppState{counter: Cell::new(0)}) + || App::with_state(AppState{counter: Cell::new(0)}) // enable logger .middleware(middleware::Logger::default()) // websocket route diff --git a/examples/template_tera/src/main.rs b/examples/template_tera/src/main.rs index e10072553..fb512d2c4 100644 --- a/examples/template_tera/src/main.rs +++ b/examples/template_tera/src/main.rs @@ -5,9 +5,7 @@ extern crate env_logger; extern crate tera; use actix_web::{ - http, error, middleware, server, - Application, HttpRequest, HttpResponse, Error, -}; + http, error, middleware, server, App, HttpRequest, HttpResponse, Error}; struct State { @@ -38,7 +36,7 @@ fn main() { let _ = server::new(|| { let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")); - Application::with_state(State{template: tera}) + App::with_state(State{template: tera}) // enable logger .middleware(middleware::Logger::default()) .resource("/", |r| r.method(http::Method::GET).f(index))}) diff --git a/examples/tls/src/main.rs b/examples/tls/src/main.rs index 8fa00abcc..809af1716 100644 --- a/examples/tls/src/main.rs +++ b/examples/tls/src/main.rs @@ -6,8 +6,7 @@ extern crate openssl; use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype}; use actix_web::{ - http, middleware, server, - Application, HttpRequest, HttpResponse, Error}; + http, middleware, server, App, HttpRequest, HttpResponse, Error}; /// simple handle @@ -31,7 +30,7 @@ fn main() { builder.set_certificate_chain_file("cert.pem").unwrap(); let _ = server::new( - || Application::new() + || App::new() // enable logger .middleware(middleware::Logger::default()) // register simple handler, handle all methods diff --git a/examples/unix-socket/src/main.rs b/examples/unix-socket/src/main.rs index a56d428a7..aeb749d10 100644 --- a/examples/unix-socket/src/main.rs +++ b/examples/unix-socket/src/main.rs @@ -14,12 +14,13 @@ fn index(_req: HttpRequest) -> &'static str { fn main() { ::std::env::set_var("RUST_LOG", "actix_web=info"); - let _ = env_logger::init(); + env_logger::init(); let sys = actix::System::new("unix-socket"); - let listener = UnixListener::bind("/tmp/actix-uds.socket", Arbiter::handle()).expect("bind failed"); - let _addr = HttpServer::new( - || Application::new() + let listener = UnixListener::bind( + "/tmp/actix-uds.socket", Arbiter::handle()).expect("bind failed"); + HttpServer::new( + || App::new() // enable logger .middleware(middleware::Logger::default()) .resource("/index.html", |r| r.f(|_| "Hello world!")) diff --git a/examples/web-cors/backend/src/main.rs b/examples/web-cors/backend/src/main.rs index bbfc4e0af..599be2c94 100644 --- a/examples/web-cors/backend/src/main.rs +++ b/examples/web-cors/backend/src/main.rs @@ -7,7 +7,7 @@ extern crate actix_web; extern crate env_logger; use std::env; -use actix_web::{http, middleware, server, Application}; +use actix_web::{http, middleware, server, App}; mod user; use user::info; @@ -20,7 +20,7 @@ fn main() { let sys = actix::System::new("Actix-web-CORS"); server::new( - || Application::new() + || App::new() .middleware(middleware::Logger::default()) .resource("/user/info", |r| { middleware::cors::Cors::build() diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index df5ade3be..1de3900c4 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -17,9 +17,7 @@ extern crate actix_web; use std::time::Instant; use actix::*; -use actix_web::{ - http, fs, ws, - Application, HttpRequest, HttpResponse, HttpServer, Error}; +use actix_web::{http, fs, ws, App, HttpRequest, HttpResponse, HttpServer, Error}; mod codec; mod server; @@ -190,7 +188,7 @@ fn main() { // Websocket sessions state let state = WsChatSessionState { addr: server.clone() }; - Application::with_state(state) + App::with_state(state) // redirect to websocket.html .resource("/", |r| r.method(http::Method::GET).f(|_| { HttpResponse::Found() diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs index 201909f58..bcf2ee7ba 100644 --- a/examples/websocket/src/main.rs +++ b/examples/websocket/src/main.rs @@ -10,9 +10,7 @@ extern crate env_logger; use actix::prelude::*; use actix_web::{ - http, middleware, server, fs, ws, - Application, HttpRequest, HttpResponse, Error, -}; + http, middleware, server, fs, ws, App, HttpRequest, HttpResponse, Error}; /// do websocket handshake and start `MyWebSocket` actor fn ws_index(r: HttpRequest) -> Result { @@ -51,7 +49,7 @@ fn main() { let sys = actix::System::new("ws-example"); server::new( - || Application::new() + || App::new() // enable logger .middleware(middleware::Logger::default()) // websocket route diff --git a/guide/src/qs_10.md b/guide/src/qs_10.md index f83422845..c69d26f68 100644 --- a/guide/src/qs_10.md +++ b/guide/src/qs_10.md @@ -23,7 +23,7 @@ Here is an example of a simple middleware that adds request and response headers # extern crate http; # extern crate actix_web; use http::{header, HttpTryFrom}; -use actix_web::{Application, HttpRequest, HttpResponse, Result}; +use actix_web::{App, HttpRequest, HttpResponse, Result}; use actix_web::middleware::{Middleware, Started, Response}; struct Headers; // <- Our middleware @@ -51,7 +51,7 @@ impl Middleware for Headers { } fn main() { - Application::new() + App::new() .middleware(Headers) // <- Register middleware, this method can be called multiple times .resource("/", |r| r.f(|_| HttpResponse::Ok())); } @@ -79,14 +79,14 @@ Default `Logger` can be created with `default` method, it uses the default forma ```rust # extern crate actix_web; extern crate env_logger; -use actix_web::Application; +use actix_web::App; use actix_web::middleware::Logger; fn main() { std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); - Application::new() + App::new() .middleware(Logger::default()) .middleware(Logger::new("%a %{User-Agent}i")) .finish(); @@ -135,10 +135,10 @@ the specified header. ```rust # extern crate actix_web; -use actix_web::{http, middleware, Application, HttpResponse}; +use actix_web::{http, middleware, App, HttpResponse}; fn main() { - let app = Application::new() + let app = App::new() .middleware( middleware::DefaultHeaders::build() .header("X-Version", "0.2") @@ -198,7 +198,7 @@ fn index(mut req: HttpRequest) -> Result<&'static str> { fn main() { # let sys = actix::System::new("basic-example"); HttpServer::new( - || Application::new() + || App::new() .middleware(SessionStorage::new( // <- create session middleware CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend .secure(false) diff --git a/guide/src/qs_12.md b/guide/src/qs_12.md index 2a7e18291..1da5f1ef9 100644 --- a/guide/src/qs_12.md +++ b/guide/src/qs_12.md @@ -8,7 +8,7 @@ match path tail we can use `[.*]` regex. ```rust # extern crate actix_web; use std::path::PathBuf; -use actix_web::{Application, HttpRequest, Result, http::Method, fs::NamedFile}; +use actix_web::{App, HttpRequest, Result, http::Method, fs::NamedFile}; fn index(req: HttpRequest) -> Result { let path: PathBuf = req.match_info().query("tail")?; @@ -16,7 +16,7 @@ fn index(req: HttpRequest) -> Result { } fn main() { - Application::new() + App::new() .resource(r"/a/{tail:.*}", |r| r.method(Method::GET).f(index)) .finish(); } @@ -25,7 +25,7 @@ fn main() { ## Directory To serve files from specific directory and sub-directories `StaticFiles` could be used. -`StaticFiles` must be registered with `Application::handler()` method otherwise +`StaticFiles` must be registered with `App::handler()` method otherwise it won't be able to serve sub-paths. ```rust @@ -33,7 +33,7 @@ it won't be able to serve sub-paths. use actix_web::*; fn main() { - Application::new() + App::new() .handler("/static", fs::StaticFiles::new(".", true)) .finish(); } diff --git a/guide/src/qs_13.md b/guide/src/qs_13.md index 1e38d56a0..753a9c16f 100644 --- a/guide/src/qs_13.md +++ b/guide/src/qs_13.md @@ -28,7 +28,7 @@ fn main() { builder.set_certificate_chain_file("cert.pem").unwrap(); HttpServer::new( - || Application::new() + || App::new() .resource("/index.html", |r| r.f(index))) .bind("127.0.0.1:8080").unwrap(); .serve_ssl(builder).unwrap(); diff --git a/guide/src/qs_14.md b/guide/src/qs_14.md index efb8ba732..a805e7a58 100644 --- a/guide/src/qs_14.md +++ b/guide/src/qs_14.md @@ -87,7 +87,7 @@ fn main() { // Start http server HttpServer::new(move || { - Application::with_state(State{db: addr.clone()}) + App::with_state(State{db: addr.clone()}) .resource("/{name}", |r| r.method(Method::GET).a(index))}) .bind("127.0.0.1:8080").unwrap() .start().unwrap(); diff --git a/guide/src/qs_2.md b/guide/src/qs_2.md index 8243f8693..e405775d4 100644 --- a/guide/src/qs_2.md +++ b/guide/src/qs_2.md @@ -48,7 +48,7 @@ request handler with the application's `resource` on a particular *HTTP method* # "Hello world!" # } # fn main() { - Application::new() + App::new() .resource("/", |r| r.f(index)); # } ``` @@ -58,7 +58,7 @@ connections. The server accepts a function that should return an `HttpHandler` i ```rust,ignore HttpServer::new( - || Application::new() + || App::new() .resource("/", |r| r.f(index))) .bind("127.0.0.1:8088")? .run(); @@ -72,7 +72,7 @@ Here is full source of main.rs file: ```rust # use std::thread; extern crate actix_web; -use actix_web::{Application, HttpRequest, HttpResponse, HttpServer}; +use actix_web::{App, HttpRequest, HttpResponse, HttpServer}; fn index(req: HttpRequest) -> &'static str { "Hello world!" @@ -84,7 +84,7 @@ fn main() { # // call. # thread::spawn(|| { HttpServer::new( - || Application::new() + || App::new() .resource("/", |r| r.f(index))) .bind("127.0.0.1:8088").expect("Can not bind to 127.0.0.1:8088") .run(); diff --git a/guide/src/qs_3.md b/guide/src/qs_3.md index 7b39b4efc..bcfdee8ad 100644 --- a/guide/src/qs_3.md +++ b/guide/src/qs_3.md @@ -4,7 +4,7 @@ Actix web provides some primitives to build web servers and applications with Ru It provides routing, middlewares, pre-processing of requests, and post-processing of responses, websocket protocol handling, multipart streams, etc. -All actix web servers are built around the `Application` instance. +All actix web servers are built around the `App` instance. It is used for registering routes for resources, and middlewares. It also stores application specific state that is shared across all handlers within same application. @@ -24,7 +24,7 @@ but path `/application` would not match. # "Hello world!" # } # fn main() { - let app = Application::new() + let app = App::new() .prefix("/app") .resource("/index.html", |r| r.method(Method::GET).f(index)) .finish() @@ -43,17 +43,17 @@ Multiple applications can be served with one server: # extern crate tokio_core; # use tokio_core::net::TcpStream; # use std::net::SocketAddr; -use actix_web::{Application, HttpResponse, HttpServer}; +use actix_web::{App, HttpResponse, HttpServer}; fn main() { HttpServer::new(|| vec![ - Application::new() + App::new() .prefix("/app1") .resource("/", |r| r.f(|r| HttpResponse::Ok())), - Application::new() + App::new() .prefix("/app2") .resource("/", |r| r.f(|r| HttpResponse::Ok())), - Application::new() + App::new() .resource("/", |r| r.f(|r| HttpResponse::Ok())), ]); } @@ -81,7 +81,7 @@ in the state: # extern crate actix_web; # use std::cell::Cell; -use actix_web::{Application, HttpRequest, http}; +use actix_web::{App, HttpRequest, http}; // This struct represents state struct AppState { @@ -96,7 +96,7 @@ fn index(req: HttpRequest) -> String { } fn main() { - Application::with_state(AppState{counter: Cell::new(0)}) + App::with_state(AppState{counter: Cell::new(0)}) .resource("/", |r| r.method(http::Method::GET).f(index)) .finish(); } diff --git a/guide/src/qs_3_5.md b/guide/src/qs_3_5.md index 8b2951022..274524024 100644 --- a/guide/src/qs_3_5.md +++ b/guide/src/qs_3_5.md @@ -13,13 +13,13 @@ within a properly configured actix system: # extern crate actix; # extern crate actix_web; use actix::*; -use actix_web::{server, Application, HttpResponse}; +use actix_web::{server, App, HttpResponse}; fn main() { let sys = actix::System::new("guide"); server::new( - || Application::new() + || App::new() .resource("/", |r| r.f(|_| HttpResponse::Ok()))) .bind("127.0.0.1:59080").unwrap() .start(); @@ -49,7 +49,7 @@ address of the started http server. Actix http server accepts several messages: use std::thread; use std::sync::mpsc; use actix::*; -use actix_web::{server, Application, HttpResponse, HttpServer}; +use actix_web::{server, App, HttpResponse, HttpServer}; fn main() { let (tx, rx) = mpsc::channel(); @@ -57,7 +57,7 @@ fn main() { thread::spawn(move || { let sys = actix::System::new("http-server"); let addr = server::new( - || Application::new() + || App::new() .resource("/", |r| r.f(|_| HttpResponse::Ok()))) .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0") .shutdown_timeout(60) // <- Set shutdown timeout to 60 seconds @@ -81,11 +81,11 @@ can be overridden with the `HttpServer::threads()` method. ```rust # extern crate actix_web; # extern crate tokio_core; -use actix_web::{Application, HttpServer, HttpResponse}; +use actix_web::{App, HttpServer, HttpResponse}; fn main() { HttpServer::new( - || Application::new() + || App::new() .resource("/", |r| r.f(|_| HttpResponse::Ok()))) .threads(4); // <- Start 4 workers } @@ -116,7 +116,7 @@ fn main() { builder.set_certificate_chain_file("cert.pem").unwrap(); HttpServer::new( - || Application::new() + || App::new() .resource("/index.html", |r| r.f(index))) .bind("127.0.0.1:8080").unwrap() .serve_ssl(builder).unwrap(); @@ -143,21 +143,21 @@ connection behavior is defined by server settings. ```rust # extern crate actix_web; # extern crate tokio_core; -use actix_web::{server, Application, HttpResponse}; +use actix_web::{server, App, HttpResponse}; fn main() { server::new(|| - Application::new() + App::new() .resource("/", |r| r.f(|_| HttpResponse::Ok()))) .keep_alive(75); // <- Set keep-alive to 75 seconds server::new(|| - Application::new() + App::new() .resource("/", |r| r.f(|_| HttpResponse::Ok()))) .keep_alive(server::KeepAlive::Tcp(75)); // <- Use `SO_KEEPALIVE` socket option. server::new(|| - Application::new() + App::new() .resource("/", |r| r.f(|_| HttpResponse::Ok()))) .keep_alive(None); // <- Disable keep-alive } diff --git a/guide/src/qs_4.md b/guide/src/qs_4.md index 919ae5b8f..5c31a78f5 100644 --- a/guide/src/qs_4.md +++ b/guide/src/qs_4.md @@ -53,7 +53,7 @@ Here is an example of a handler that stores the number of processed requests: ```rust # extern crate actix_web; -use actix_web::{Application, HttpRequest, HttpResponse, dev::Handler}; +use actix_web::{App, HttpRequest, HttpResponse, dev::Handler}; struct MyHandler(usize); @@ -75,7 +75,7 @@ number of requests processed per thread. A proper implementation would use `Arc` ```rust # extern crate actix; # extern crate actix_web; -use actix_web::{server, Application, HttpRequest, HttpResponse, dev::Handler}; +use actix_web::{server, App, HttpRequest, HttpResponse, dev::Handler}; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -99,7 +99,7 @@ fn main() { server::new( move || { let cloned = inc.clone(); - Application::new() + App::new() .resource("/", move |r| r.h(MyHandler(cloned))) }) .bind("127.0.0.1:8088").unwrap() @@ -127,7 +127,7 @@ Let's create a response for a custom type that serializes to an `application/jso extern crate serde; extern crate serde_json; #[macro_use] extern crate serde_derive; -use actix_web::{Application, HttpServer, HttpRequest, HttpResponse, Error, Responder, http}; +use actix_web::{App, HttpServer, HttpRequest, HttpResponse, Error, Responder, http}; #[derive(Serialize)] struct MyObj { @@ -158,7 +158,7 @@ fn main() { let sys = actix::System::new("example"); HttpServer::new( - || Application::new() + || App::new() .resource("/", |r| r.method(http::Method::GET).f(index))) .bind("127.0.0.1:8088").unwrap() .start(); @@ -198,7 +198,7 @@ fn index2(req: HttpRequest) -> Box> { } fn main() { - Application::new() + App::new() .resource("/async", |r| r.route().a(index)) .resource("/", |r| r.route().a(index2)) .finish(); @@ -224,7 +224,7 @@ fn index(req: HttpRequest) -> HttpResponse { } fn main() { - Application::new() + App::new() .resource("/async", |r| r.f(index)) .finish(); } @@ -257,7 +257,7 @@ fn index(req: HttpRequest) -> Result> # # fn is_error() -> bool { true } # fn main() { -# Application::new() +# App::new() # .resource("/async", |r| r.route().f(index)) # .finish(); # } @@ -294,7 +294,7 @@ fn index(req: HttpRequest) -> RegisterResult { } # fn is_a_variant() -> bool { true } # fn main() { -# Application::new() +# App::new() # .resource("/register", |r| r.f(index)) # .finish(); # } diff --git a/guide/src/qs_4_5.md b/guide/src/qs_4_5.md index 26b30fa3a..cf8c6ef36 100644 --- a/guide/src/qs_4_5.md +++ b/guide/src/qs_4_5.md @@ -27,7 +27,7 @@ fn index(req: HttpRequest) -> io::Result { } # # fn main() { -# Application::new() +# App::new() # .resource(r"/a/index.html", |r| r.f(index)) # .finish(); # } @@ -58,7 +58,7 @@ fn index(req: HttpRequest) -> Result<&'static str, MyError> { } # # fn main() { -# Application::new() +# App::new() # .resource(r"/a/index.html", |r| r.f(index)) # .finish(); # } @@ -70,7 +70,7 @@ to return different responses for different types of errors. ```rust # extern crate actix_web; #[macro_use] extern crate failure; -use actix_web::{Application, HttpRequest, HttpResponse, http, error}; +use actix_web::{App, HttpRequest, HttpResponse, http, error}; #[derive(Fail, Debug)] enum MyError { @@ -100,7 +100,7 @@ fn index(req: HttpRequest) -> Result<&'static str, MyError> { } # # fn main() { -# Application::new() +# App::new() # .resource(r"/a/index.html", |r| r.f(index)) # .finish(); # } @@ -127,7 +127,7 @@ fn index(req: HttpRequest) -> Result<&'static str> { Ok(result.map_err(|e| error::ErrorBadRequest(e))?) } # fn main() { -# Application::new() +# App::new() # .resource(r"/a/index.html", |r| r.f(index)) # .finish(); # } diff --git a/guide/src/qs_5.md b/guide/src/qs_5.md index dad57f6b1..67b3be79d 100644 --- a/guide/src/qs_5.md +++ b/guide/src/qs_5.md @@ -15,20 +15,20 @@ A resource also has a pattern, meant to match against the *PATH* portion of a *U it does not match against the *QUERY* portion (the portion following the scheme and port, e.g., */foo/bar* in the *URL* *http://localhost:8080/foo/bar?q=value*). -The [Application::resource](../actix_web/struct.Application.html#method.resource) methods +The [App::resource](../actix_web/struct.App.html#method.resource) methods add a single resource to application routing table. This method accepts a *path pattern* and a resource configuration function. ```rust # extern crate actix_web; -# use actix_web::{Application, HttpRequest, HttpResponse, http::Method}; +# use actix_web::{App, HttpRequest, HttpResponse, http::Method}; # # fn index(req: HttpRequest) -> HttpResponse { # unimplemented!() # } # fn main() { - Application::new() + App::new() .resource("/prefix", |r| r.f(index)) .resource("/user/{name}", |r| r.method(Method::GET).f(|req| HttpResponse::Ok())) @@ -63,7 +63,7 @@ any number of *predicates* but only one handler. # use actix_web::*; fn main() { - Application::new() + App::new() .resource("/path", |resource| resource.route() .filter(pred::Get()) @@ -108,7 +108,7 @@ against a URL path pattern. `path` represents the path portion of the URL that w The way that *actix* does this is very simple. When a request enters the system, for each resource configuration declaration present in the system, actix checks the request's path against the pattern declared. This checking happens in the order that -the routes were declared via `Application::resource()` method. If resource can not be found, +the routes were declared via `App::resource()` method. If resource can not be found, the *default resource* is used as the matched resource. When a route configuration is declared, it may contain route predicate arguments. All route @@ -277,7 +277,7 @@ fn index(req: HttpRequest) -> Result { } fn main() { - Application::new() + App::new() .resource(r"/a/{v1}/{v2}/", |r| r.f(index)) .finish(); } @@ -304,7 +304,7 @@ safe to interpolate within, or use as a suffix of, a path without additional che ```rust # extern crate actix_web; use std::path::PathBuf; -use actix_web::{Application, HttpRequest, Result, http::Method}; +use actix_web::{App, HttpRequest, Result, http::Method}; fn index(req: HttpRequest) -> Result { let path: PathBuf = req.match_info().query("tail")?; @@ -312,7 +312,7 @@ fn index(req: HttpRequest) -> Result { } fn main() { - Application::new() + App::new() .resource(r"/a/{tail:.*}", |r| r.method(Method::GET).f(index)) .finish(); } @@ -333,7 +333,7 @@ has to implement *serde's *`Deserialize` trait. # extern crate actix_web; # extern crate futures; #[macro_use] extern crate serde_derive; -use actix_web::{Application, Path, Result, http::Method}; +use actix_web::{App, Path, Result, http::Method}; #[derive(Deserialize)] struct Info { @@ -346,7 +346,7 @@ fn index(info: Path) -> Result { } fn main() { - let app = Application::new() + let app = App::new() .resource("/{username}/index.html", // <- define path parameters |r| r.method(Method::GET).with(index)); } @@ -364,7 +364,7 @@ resource with the name "foo" and the pattern "{a}/{b}/{c}", you might do this: ```rust # extern crate actix_web; -# use actix_web::{Application, HttpRequest, HttpResponse, http::Method}; +# use actix_web::{App, HttpRequest, HttpResponse, http::Method}; # fn index(req: HttpRequest) -> HttpResponse { let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource @@ -372,7 +372,7 @@ fn index(req: HttpRequest) -> HttpResponse { } fn main() { - let app = Application::new() + let app = App::new() .resource("/test/{a}/{b}/{c}", |r| { r.name("foo"); // <- set resource name, then it could be used in `url_for` r.method(Method::GET).f(|_| HttpResponse::Ok()); @@ -394,7 +394,7 @@ for URL generation purposes only and are never considered for matching at reques ```rust # extern crate actix_web; -use actix_web::{Application, HttpRequest, HttpResponse, Error}; +use actix_web::{App, HttpRequest, HttpResponse, Error}; fn index(mut req: HttpRequest) -> Result { let url = req.url_for("youtube", &["oHg5SJYRHA0"])?; @@ -403,7 +403,7 @@ fn index(mut req: HttpRequest) -> Result { } fn main() { - let app = Application::new() + let app = App::new() .resource("/index.html", |r| r.f(index)) .external_resource("youtube", "https://youtube.com/watch/{video_id}") .finish(); @@ -440,7 +440,7 @@ use actix_web::http::NormalizePath; # HttpResponse::Ok().into() # } fn main() { - let app = Application::new() + let app = App::new() .resource("/resource/", |r| r.f(index)) .default_resource(|r| r.h(NormalizePath::default())) .finish(); @@ -459,13 +459,13 @@ It is possible to register path normalization only for *GET* requests only: ```rust # extern crate actix_web; # #[macro_use] extern crate serde_derive; -use actix_web::{Application, HttpRequest, http::Method, http::NormalizePath}; +use actix_web::{App, HttpRequest, http::Method, http::NormalizePath}; # # fn index(req: HttpRequest) -> &'static str { # "test" # } fn main() { - let app = Application::new() + let app = App::new() .resource("/resource/", |r| r.f(index)) .default_resource(|r| r.method(Method::GET).h(NormalizePath::default())) .finish(); @@ -474,7 +474,7 @@ fn main() { ## Using an Application Prefix to Compose Applications -The `Application::prefix()`" method allows to set a specific application prefix. +The `App::prefix()`" method allows to set a specific application prefix. This prefix represents a resource prefix that will be prepended to all resource patterns added by the resource configuration. This can be used to help mount a set of routes at a different location than the included callable's author intended while still maintaining the same @@ -491,7 +491,7 @@ fn show_users(req: HttpRequest) -> HttpResponse { } fn main() { - Application::new() + App::new() .prefix("/users") .resource("/show", |r| r.f(show_users)) .finish(); @@ -517,7 +517,7 @@ Here is a simple predicate that check that a request contains a specific *header ```rust # extern crate actix_web; # use actix_web::*; -use actix_web::{http, pred::Predicate, Application, HttpRequest}; +use actix_web::{http, pred::Predicate, App, HttpRequest}; struct ContentTypeHeader; @@ -529,7 +529,7 @@ impl Predicate for ContentTypeHeader { } fn main() { - Application::new() + App::new() .resource("/index.html", |r| r.route() .filter(ContentTypeHeader) @@ -553,10 +553,10 @@ except "GET": # extern crate actix_web; # extern crate http; # use actix_web::*; -use actix_web::{pred, Application, HttpResponse}; +use actix_web::{pred, App, HttpResponse}; fn main() { - Application::new() + App::new() .resource("/index.html", |r| r.route() .filter(pred::Not(pred::Get())) @@ -583,16 +583,16 @@ predicates match. i.e: If the path pattern can not be found in the routing table or a resource can not find matching route, the default resource is used. The default response is *NOT FOUND*. -It is possible to override the *NOT FOUND* response with `Application::default_resource()`. +It is possible to override the *NOT FOUND* response with `App::default_resource()`. This method accepts a *configuration function* same as normal resource configuration -with `Application::resource()` method. +with `App::resource()` method. ```rust # extern crate actix_web; -use actix_web::{Application, HttpResponse, http::Method, pred}; +use actix_web::{App, HttpResponse, http::Method, pred}; fn main() { - Application::new() + App::new() .default_resource(|r| { r.method(Method::GET).f(|req| HttpResponse::NotFound()); r.route().filter(pred::Not(pred::Get())) diff --git a/guide/src/qs_7.md b/guide/src/qs_7.md index 4cd5e448f..d841f2bd8 100644 --- a/guide/src/qs_7.md +++ b/guide/src/qs_7.md @@ -135,7 +135,7 @@ type `T` must implement the `Serialize` trait from *serde*. ```rust # extern crate actix_web; #[macro_use] extern crate serde_derive; -use actix_web::{Application, HttpRequest, Json, Result, http::Method}; +use actix_web::{App, HttpRequest, Json, Result, http::Method}; #[derive(Serialize)] struct MyObj { @@ -147,7 +147,7 @@ fn index(req: HttpRequest) -> Result> { } fn main() { - Application::new() + App::new() .resource(r"/a/{name}", |r| r.method(Method::GET).f(index)) .finish(); } diff --git a/guide/src/qs_8.md b/guide/src/qs_8.md index 7e644c741..380f9e0e7 100644 --- a/guide/src/qs_8.md +++ b/guide/src/qs_8.md @@ -75,15 +75,15 @@ function same way as you would for real http server configuration. ```rust # extern crate actix_web; -use actix_web::{http, test, Application, HttpRequest, HttpResponse}; +use actix_web::{http, test, App, HttpRequest, HttpResponse}; fn index(req: HttpRequest) -> HttpResponse { HttpResponse::Ok().into() } /// This function get called by http server. -fn create_app() -> Application { - Application::new() +fn create_app() -> App { + App::new() .resource("/test", |r| r.h(index)) } diff --git a/guide/src/qs_9.md b/guide/src/qs_9.md index 676db8b8e..158ba2513 100644 --- a/guide/src/qs_9.md +++ b/guide/src/qs_9.md @@ -35,7 +35,7 @@ impl StreamHandler for Ws { } fn main() { - Application::new() + App::new() .resource("/ws/", |r| r.f(|req| ws::start(req, Ws))) // <- register websocket route .finish(); } diff --git a/src/application.rs b/src/application.rs index 216965e66..ad232a798 100644 --- a/src/application.rs +++ b/src/application.rs @@ -13,6 +13,9 @@ use pipeline::{Pipeline, PipelineHandler}; use middleware::Middleware; use server::{HttpHandler, IntoHttpHandler, HttpHandlerTask, ServerSettings}; +#[deprecated(since="0.5.0", note="please use `actix_web::App` instead")] +pub type Application = App; + /// Application pub struct HttpApplication { state: Rc, @@ -108,17 +111,17 @@ struct ApplicationParts { middlewares: Vec>>, } -/// Structure that follows the builder pattern for building `Application` structs. -pub struct Application { +/// Structure that follows the builder pattern for building application instances. +pub struct App { parts: Option>, } -impl Application<()> { +impl App<()> { /// Create application with empty state. Application can /// be configured with builder-like pattern. - pub fn new() -> Application<()> { - Application { + pub fn new() -> App<()> { + App { parts: Some(ApplicationParts { state: (), prefix: "/".to_owned(), @@ -134,21 +137,21 @@ impl Application<()> { } } -impl Default for Application<()> { +impl Default for App<()> { fn default() -> Self { - Application::new() + App::new() } } -impl Application where S: 'static { +impl App where S: 'static { /// Create application with specific state. Application can be /// configured with builder-like pattern. /// /// State is shared with all resources within same application and could be /// accessed with `HttpRequest::state()` method. - pub fn with_state(state: S) -> Application { - Application { + pub fn with_state(state: S) -> App { + App { parts: Some(ApplicationParts { state, prefix: "/".to_owned(), @@ -178,10 +181,10 @@ impl Application where S: 'static { /// /// ```rust /// # extern crate actix_web; - /// use actix_web::{http, Application, HttpResponse}; + /// use actix_web::{http, App, HttpResponse}; /// /// fn main() { - /// let app = Application::new() + /// let app = App::new() /// .prefix("/app") /// .resource("/test", |r| { /// r.method(http::Method::GET).f(|_| HttpResponse::Ok()); @@ -190,7 +193,7 @@ impl Application where S: 'static { /// .finish(); /// } /// ``` - pub fn prefix>(mut self, prefix: P) -> Application { + pub fn prefix>(mut self, prefix: P) -> App { { let parts = self.parts.as_mut().expect("Use after finish"); let mut prefix = prefix.into(); @@ -222,17 +225,17 @@ impl Application where S: 'static { /// /// ```rust /// # extern crate actix_web; - /// use actix_web::{http, Application, HttpResponse}; + /// use actix_web::{http, App, HttpResponse}; /// /// fn main() { - /// let app = Application::new() + /// let app = App::new() /// .resource("/test", |r| { /// r.method(http::Method::GET).f(|_| HttpResponse::Ok()); /// r.method(http::Method::HEAD).f(|_| HttpResponse::MethodNotAllowed()); /// }); /// } /// ``` - pub fn resource(mut self, path: &str, f: F) -> Application + pub fn resource(mut self, path: &str, f: F) -> App where F: FnOnce(&mut Resource) + 'static { { @@ -249,7 +252,7 @@ impl Application where S: 'static { } /// Default resource is used if no matched route could be found. - pub fn default_resource(mut self, f: F) -> Application + pub fn default_resource(mut self, f: F) -> App where F: FnOnce(&mut Resource) + 'static { { @@ -260,7 +263,7 @@ impl Application where S: 'static { } /// Set default content encoding. `ContentEncoding::Auto` is set by default. - pub fn default_encoding(mut self, encoding: ContentEncoding) -> Application + pub fn default_encoding(mut self, encoding: ContentEncoding) -> App { { let parts = self.parts.as_mut().expect("Use after finish"); @@ -277,7 +280,7 @@ impl Application where S: 'static { /// /// ```rust /// # extern crate actix_web; - /// use actix_web::{Application, HttpRequest, HttpResponse, Result}; + /// use actix_web::{App, HttpRequest, HttpResponse, Result}; /// /// fn index(mut req: HttpRequest) -> Result { /// let url = req.url_for("youtube", &["oHg5SJYRHA0"])?; @@ -286,13 +289,13 @@ impl Application where S: 'static { /// } /// /// fn main() { - /// let app = Application::new() + /// let app = App::new() /// .resource("/index.html", |r| r.f(index)) /// .external_resource("youtube", "https://youtube.com/watch/{video_id}") /// .finish(); /// } /// ``` - pub fn external_resource(mut self, name: T, url: U) -> Application + pub fn external_resource(mut self, name: T, url: U) -> App where T: AsRef, U: AsRef { { @@ -315,10 +318,10 @@ impl Application where S: 'static { /// /// ```rust /// # extern crate actix_web; - /// use actix_web::{http, Application, HttpRequest, HttpResponse}; + /// use actix_web::{http, App, HttpRequest, HttpResponse}; /// /// fn main() { - /// let app = Application::new() + /// let app = App::new() /// .handler("/app", |req: HttpRequest| { /// match *req.method() { /// http::Method::GET => HttpResponse::Ok(), @@ -327,7 +330,7 @@ impl Application where S: 'static { /// }}); /// } /// ``` - pub fn handler>(mut self, path: &str, handler: H) -> Application + pub fn handler>(mut self, path: &str, handler: H) -> App { { let path = path.trim().trim_right_matches('/').to_owned(); @@ -338,7 +341,7 @@ impl Application where S: 'static { } /// Register a middleware - pub fn middleware>(mut self, mw: M) -> Application { + pub fn middleware>(mut self, mw: M) -> App { self.parts.as_mut().expect("Use after finish") .middlewares.push(Box::new(mw)); self @@ -352,10 +355,10 @@ impl Application where S: 'static { /// /// ```rust /// # extern crate actix_web; - /// use actix_web::{Application, HttpResponse, http, fs, middleware}; + /// use actix_web::{App, HttpResponse, http, fs, middleware}; /// /// // this function could be located in different module - /// fn config(app: Application) -> Application { + /// fn config(app: App) -> App { /// app /// .resource("/test", |r| { /// r.method(http::Method::GET).f(|_| HttpResponse::Ok()); @@ -364,14 +367,14 @@ impl Application where S: 'static { /// } /// /// fn main() { - /// let app = Application::new() + /// let app = App::new() /// .middleware(middleware::Logger::default()) /// .configure(config) // <- register resources /// .handler("/static", fs::StaticFiles::new(".", true)); /// } /// ``` - pub fn configure(self, cfg: F) -> Application - where F: Fn(Application) -> Application + pub fn configure(self, cfg: F) -> App + where F: Fn(App) -> App { cfg(self) } @@ -410,7 +413,7 @@ impl Application where S: 'static { /// Convenience method for creating `Box` instance. /// - /// This method is useful if you need to register several application instances + /// This method is useful if you need to register multiple application instances /// with different state. /// /// ```rust @@ -425,11 +428,11 @@ impl Application where S: 'static { /// fn main() { /// # thread::spawn(|| { /// HttpServer::new(|| { vec![ - /// Application::with_state(State1) + /// App::with_state(State1) /// .prefix("/app1") /// .resource("/", |r| r.f(|r| HttpResponse::Ok())) /// .boxed(), - /// Application::with_state(State2) + /// App::with_state(State2) /// .prefix("/app2") /// .resource("/", |r| r.f(|r| HttpResponse::Ok())) /// .boxed() ]}) @@ -443,7 +446,7 @@ impl Application where S: 'static { } } -impl IntoHttpHandler for Application { +impl IntoHttpHandler for App { type Handler = HttpApplication; fn into_handler(mut self, settings: ServerSettings) -> HttpApplication { @@ -455,7 +458,7 @@ impl IntoHttpHandler for Application { } } -impl<'a, S: 'static> IntoHttpHandler for &'a mut Application { +impl<'a, S: 'static> IntoHttpHandler for &'a mut App { type Handler = HttpApplication; fn into_handler(self, settings: ServerSettings) -> HttpApplication { @@ -468,7 +471,7 @@ impl<'a, S: 'static> IntoHttpHandler for &'a mut Application { } #[doc(hidden)] -impl Iterator for Application { +impl Iterator for App { type Item = HttpApplication; fn next(&mut self) -> Option { @@ -491,7 +494,7 @@ mod tests { #[test] fn test_default_resource() { - let mut app = Application::new() + let mut app = App::new() .resource("/test", |r| r.f(|_| HttpResponse::Ok())) .finish(); @@ -503,7 +506,7 @@ mod tests { let resp = app.run(req); assert_eq!(resp.as_response().unwrap().status(), StatusCode::NOT_FOUND); - let mut app = Application::new() + let mut app = App::new() .default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed())) .finish(); let req = TestRequest::with_uri("/blah").finish(); @@ -513,7 +516,7 @@ mod tests { #[test] fn test_unhandled_prefix() { - let mut app = Application::new() + let mut app = App::new() .prefix("/test") .resource("/test", |r| r.f(|_| HttpResponse::Ok())) .finish(); @@ -522,7 +525,7 @@ mod tests { #[test] fn test_state() { - let mut app = Application::with_state(10) + let mut app = App::with_state(10) .resource("/", |r| r.f(|_| HttpResponse::Ok())) .finish(); let req = HttpRequest::default().with_state(Rc::clone(&app.state), app.router.clone()); @@ -532,7 +535,7 @@ mod tests { #[test] fn test_prefix() { - let mut app = Application::new() + let mut app = App::new() .prefix("/test") .resource("/blah", |r| r.f(|_| HttpResponse::Ok())) .finish(); @@ -555,7 +558,7 @@ mod tests { #[test] fn test_handler() { - let mut app = Application::new() + let mut app = App::new() .handler("/test", |_| HttpResponse::Ok()) .finish(); @@ -582,7 +585,7 @@ mod tests { #[test] fn test_handler_prefix() { - let mut app = Application::new() + let mut app = App::new() .prefix("/app") .handler("/test", |_| HttpResponse::Ok()) .finish(); diff --git a/src/de.rs b/src/de.rs index cb0888fc1..ab89c7dab 100644 --- a/src/de.rs +++ b/src/de.rs @@ -19,7 +19,7 @@ use httprequest::HttpRequest; /// # extern crate actix_web; /// # extern crate futures; /// #[macro_use] extern crate serde_derive; -/// use actix_web::{Application, Path, Result, http}; +/// use actix_web::{App, Path, Result, http}; /// /// /// extract path info from "/{username}/{count}/?index.html" url /// /// {username} - deserializes to a String @@ -29,7 +29,7 @@ use httprequest::HttpRequest; /// } /// /// fn main() { -/// let app = Application::new().resource( +/// let app = App::new().resource( /// "/{username}/{count}/?index.html", // <- define path parameters /// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor /// } @@ -43,7 +43,7 @@ use httprequest::HttpRequest; /// # extern crate actix_web; /// # extern crate futures; /// #[macro_use] extern crate serde_derive; -/// use actix_web::{Application, Path, Result, http}; +/// use actix_web::{App, Path, Result, http}; /// /// #[derive(Deserialize)] /// struct Info { @@ -56,7 +56,7 @@ use httprequest::HttpRequest; /// } /// /// fn main() { -/// let app = Application::new().resource( +/// let app = App::new().resource( /// "/{username}/index.html", // <- define path parameters /// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor /// } @@ -109,7 +109,7 @@ impl FromRequest for Path /// # extern crate actix_web; /// # extern crate futures; /// #[macro_use] extern crate serde_derive; -/// use actix_web::{Application, Query, http}; +/// use actix_web::{App, Query, http}; /// /// #[derive(Deserialize)] /// struct Info { @@ -123,7 +123,7 @@ impl FromRequest for Path /// } /// /// fn main() { -/// let app = Application::new().resource( +/// let app = App::new().resource( /// "/index.html", /// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor /// } diff --git a/src/fs.rs b/src/fs.rs index 6fdd574be..2d6c0a359 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -363,15 +363,15 @@ impl Responder for Directory { /// Static files handling /// -/// `StaticFile` handler must be registered with `Application::handler()` method, +/// `StaticFile` handler must be registered with `App::handler()` method, /// because `StaticFile` handler requires access sub-path information. /// /// ```rust /// # extern crate actix_web; -/// use actix_web::{fs, Application}; +/// use actix_web::{fs, App}; /// /// fn main() { -/// let app = Application::new() +/// let app = App::new() /// .handler("/static", fs::StaticFiles::new(".", true)) /// .finish(); /// } diff --git a/src/handler.rs b/src/handler.rs index 279eef848..855df5353 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -96,7 +96,7 @@ impl Responder for Either } } -/// Convenience trait that convert `Future` object into `Boxed` future +/// Convenience trait that converts `Future` object to a `Boxed` future /// /// For example loading json from request's body is async operation. /// @@ -106,7 +106,7 @@ impl Responder for Either /// # #[macro_use] extern crate serde_derive; /// use futures::future::Future; /// use actix_web::{ -/// Application, HttpRequest, HttpResponse, HttpMessage, Error, AsyncResponder}; +/// App, HttpRequest, HttpResponse, HttpMessage, Error, AsyncResponder}; /// /// #[derive(Deserialize, Debug)] /// struct MyObj { @@ -384,10 +384,10 @@ impl RouteHandler for AsyncHandler /// # extern crate actix_web; /// # extern crate futures; /// #[macro_use] extern crate serde_derive; -/// use actix_web::{Application, Path, State, http}; +/// use actix_web::{App, Path, State, http}; /// /// /// Application state -/// struct App {msg: &'static str} +/// struct MyApp {msg: &'static str} /// /// #[derive(Deserialize)] /// struct Info { @@ -395,12 +395,12 @@ impl RouteHandler for AsyncHandler /// } /// /// /// extract path info using serde -/// fn index(state: State, info: Path) -> String { +/// fn index(state: State, info: Path) -> String { /// format!("{} {}!", state.msg, info.username) /// } /// /// fn main() { -/// let app = Application::with_state(App{msg: "Welcome"}).resource( +/// let app = App::with_state(MyApp{msg: "Welcome"}).resource( /// "/{username}/index.html", // <- define path parameters /// |r| r.method(http::Method::GET).with2(index)); // <- use `with` extractor /// } diff --git a/src/helpers.rs b/src/helpers.rs index 5d930c58c..446e717a4 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -38,7 +38,7 @@ use httpresponse::HttpResponse; /// # HttpResponse::Ok().into() /// # } /// fn main() { -/// let app = Application::new() +/// let app = App::new() /// .resource("/test/", |r| r.f(index)) /// .default_resource(|r| r.h(NormalizePath::default())) /// .finish(); @@ -155,7 +155,7 @@ mod tests { use super::*; use http::{header, Method}; use test::TestRequest; - use application::Application; + use application::App; fn index(_req: HttpRequest) -> HttpResponse { HttpResponse::new(StatusCode::OK) @@ -163,7 +163,7 @@ mod tests { #[test] fn test_normalize_path_trailing_slashes() { - let mut app = Application::new() + let mut app = App::new() .resource("/resource1", |r| r.method(Method::GET).f(index)) .resource("/resource2/", |r| r.method(Method::GET).f(index)) .default_resource(|r| r.h(NormalizePath::default())) @@ -196,7 +196,7 @@ mod tests { #[test] fn test_normalize_path_trailing_slashes_disabled() { - let mut app = Application::new() + let mut app = App::new() .resource("/resource1", |r| r.method(Method::GET).f(index)) .resource("/resource2/", |r| r.method(Method::GET).f(index)) .default_resource(|r| r.h( @@ -223,7 +223,7 @@ mod tests { #[test] fn test_normalize_path_merge_slashes() { - let mut app = Application::new() + let mut app = App::new() .resource("/resource1", |r| r.method(Method::GET).f(index)) .resource("/resource1/a/b", |r| r.method(Method::GET).f(index)) .default_resource(|r| r.h(NormalizePath::default())) @@ -263,7 +263,7 @@ mod tests { #[test] fn test_normalize_path_merge_and_append_slashes() { - let mut app = Application::new() + let mut app = App::new() .resource("/resource1", |r| r.method(Method::GET).f(index)) .resource("/resource2/", |r| r.method(Method::GET).f(index)) .resource("/resource1/a/b", |r| r.method(Method::GET).f(index)) diff --git a/src/httprequest.rs b/src/httprequest.rs index 1fd4fa0b1..4efc1f340 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -279,7 +279,7 @@ impl HttpRequest { /// /// ```rust /// # extern crate actix_web; - /// # use actix_web::{Application, HttpRequest, HttpResponse, http}; + /// # use actix_web::{App, HttpRequest, HttpResponse, http}; /// # /// fn index(req: HttpRequest) -> HttpResponse { /// let url = req.url_for("foo", &["1", "2", "3"]); // <- generate url for "foo" resource @@ -287,7 +287,7 @@ impl HttpRequest { /// } /// /// fn main() { - /// let app = Application::new() + /// 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()); diff --git a/src/httpresponse.rs b/src/httpresponse.rs index da76a8a45..1f763159d 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -314,7 +314,7 @@ impl HttpResponseBuilder { /// /// ```rust /// # extern crate actix_web; - /// use actix_web::{http, Application, HttpRequest, HttpResponse}; + /// use actix_web::{http, HttpRequest, HttpResponse}; /// /// fn index(req: HttpRequest) -> HttpResponse { /// HttpResponse::Ok() diff --git a/src/json.rs b/src/json.rs index 701dbedc6..721361ffe 100644 --- a/src/json.rs +++ b/src/json.rs @@ -51,7 +51,7 @@ use httpresponse::HttpResponse; /// # extern crate actix_web; /// # extern crate futures; /// #[macro_use] extern crate serde_derive; -/// use actix_web::{Application, Json, Result, http}; +/// use actix_web::{App, Json, Result, http}; /// /// #[derive(Deserialize)] /// struct Info { @@ -64,7 +64,7 @@ use httpresponse::HttpResponse; /// } /// /// fn main() { -/// let app = Application::new().resource( +/// let app = App::new().resource( /// "/index.html", /// |r| r.method(http::Method::POST).with(index)); // <- use `with` extractor /// } @@ -139,8 +139,7 @@ impl FromRequest for Json /// # extern crate futures; /// # #[macro_use] extern crate serde_derive; /// use futures::future::Future; -/// use actix_web::{Application, AsyncResponder, -/// HttpRequest, HttpResponse, HttpMessage, Error}; +/// use actix_web::{AsyncResponder, HttpRequest, HttpResponse, HttpMessage, Error}; /// /// #[derive(Deserialize, Debug)] /// struct MyObj { diff --git a/src/lib.rs b/src/lib.rs index 99063afd8..13c45fbd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! Actix web is a small, pragmatic, extremely fast, web framework for Rust. //! //! ```rust -//! use actix_web::{Application, HttpServer, Path}; +//! use actix_web::{App, HttpServer, Path}; //! # use std::thread; //! //! fn index(info: Path<(String, u32)>) -> String { @@ -11,7 +11,7 @@ //! fn main() { //! # thread::spawn(|| { //! HttpServer::new( -//! || Application::new() +//! || App::new() //! .resource("/{name}/{id}/index.html", |r| r.with(index))) //! .bind("127.0.0.1:8080").unwrap() //! .run(); @@ -136,7 +136,7 @@ pub use error::{Error, Result, ResponseError}; pub use body::{Body, Binary}; pub use json::Json; pub use de::{Path, Query}; -pub use application::Application; +pub use application::App; pub use httpmessage::HttpMessage; pub use httprequest::HttpRequest; pub use httpresponse::HttpResponse; @@ -147,6 +147,10 @@ pub use server::HttpServer; #[doc(hidden)] pub mod httpcodes; +#[doc(hidden)] +#[allow(deprecated)] +pub use application::Application; + #[cfg(feature="openssl")] pub(crate) const HAS_OPENSSL: bool = true; #[cfg(not(feature="openssl"))] diff --git a/src/middleware/cors.rs b/src/middleware/cors.rs index 835d01308..bfbf54a24 100644 --- a/src/middleware/cors.rs +++ b/src/middleware/cors.rs @@ -9,7 +9,7 @@ //! 2. Use any of the builder methods to set fields in the backend. //! 3. Call [finish](struct.Cors.html#method.finish) to retrieve the constructed backend. //! -//! Cors middleware could be used as parameter for `Application::middleware()` or +//! Cors middleware could be used as parameter for `App::middleware()` or //! `Resource::middleware()` methods. But you have to use `Cors::register()` method to //! support *preflight* OPTIONS request. //! @@ -18,7 +18,7 @@ //! //! ```rust //! # extern crate actix_web; -//! use actix_web::{http, Application, HttpRequest, HttpResponse}; +//! use actix_web::{http, App, HttpRequest, HttpResponse}; //! use actix_web::middleware::cors; //! //! fn index(mut req: HttpRequest) -> &'static str { @@ -26,7 +26,7 @@ //! } //! //! fn main() { -//! let app = Application::new() +//! let app = App::new() //! .resource("/index.html", |r| { //! cors::Cors::build() // <- Construct CORS middleware //! .allowed_origin("https://www.rust-lang.org/") diff --git a/src/middleware/csrf.rs b/src/middleware/csrf.rs index 15660c129..c2003ae35 100644 --- a/src/middleware/csrf.rs +++ b/src/middleware/csrf.rs @@ -22,7 +22,7 @@ //! //! ``` //! # extern crate actix_web; -//! use actix_web::{http, Application, HttpRequest, HttpResponse}; +//! use actix_web::{http, App, HttpRequest, HttpResponse}; //! use actix_web::middleware::csrf; //! //! fn handle_post(_: HttpRequest) -> &'static str { @@ -30,7 +30,7 @@ //! } //! //! fn main() { -//! let app = Application::new() +//! let app = App::new() //! .middleware( //! csrf::CsrfFilter::build() //! .allowed_origin("https://www.example.com") diff --git a/src/middleware/defaultheaders.rs b/src/middleware/defaultheaders.rs index 5a3b71c1b..068002cad 100644 --- a/src/middleware/defaultheaders.rs +++ b/src/middleware/defaultheaders.rs @@ -13,10 +13,10 @@ use middleware::{Response, Middleware}; /// /// ```rust /// # extern crate actix_web; -/// use actix_web::{http, middleware, Application, HttpResponse}; +/// use actix_web::{http, middleware, App, HttpResponse}; /// /// fn main() { -/// let app = Application::new() +/// let app = App::new() /// .middleware( /// middleware::DefaultHeaders::build() /// .header("X-Version", "0.2") diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index d1f9053d5..173abd2f8 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -29,14 +29,14 @@ use middleware::{Middleware, Started, Finished}; /// ```rust /// # extern crate actix_web; /// extern crate env_logger; -/// use actix_web::Application; +/// use actix_web::App; /// use actix_web::middleware::Logger; /// /// fn main() { /// std::env::set_var("RUST_LOG", "actix_web=info"); /// env_logger::init(); /// -/// let app = Application::new() +/// let app = App::new() /// .middleware(Logger::default()) /// .middleware(Logger::new("%a %{User-Agent}i")) /// .finish(); diff --git a/src/middleware/session.rs b/src/middleware/session.rs index e08ce03f2..c0fe80158 100644 --- a/src/middleware/session.rs +++ b/src/middleware/session.rs @@ -114,11 +114,11 @@ unsafe impl Sync for SessionImplBox {} /// ```rust /// # extern crate actix; /// # extern crate actix_web; -/// # use actix_web::middleware::{SessionStorage, CookieSessionBackend}; -/// use actix_web::*; +/// use actix_web::App; +/// use actix_web::middleware::{SessionStorage, CookieSessionBackend}; /// /// fn main() { -/// let app = Application::new().middleware( +/// let app = App::new().middleware( /// SessionStorage::new( // <- create session middleware /// CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend /// .secure(false) diff --git a/src/pred.rs b/src/pred.rs index f7c8d8266..0c7468d0d 100644 --- a/src/pred.rs +++ b/src/pred.rs @@ -20,10 +20,10 @@ pub trait Predicate { /// /// ```rust /// # extern crate actix_web; -/// use actix_web::{pred, Application, HttpResponse}; +/// use actix_web::{pred, App, HttpResponse}; /// /// fn main() { -/// Application::new() +/// App::new() /// .resource("/index.html", |r| r.route() /// .filter(pred::Any(pred::Get()).or(pred::Post())) /// .f(|r| HttpResponse::MethodNotAllowed())); diff --git a/src/resource.rs b/src/resource.rs index ddbb599b2..dd3768885 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -24,10 +24,10 @@ use with::WithHandler; /// /// ```rust /// # extern crate actix_web; -/// use actix_web::{Application, HttpResponse, http}; +/// use actix_web::{App, HttpResponse, http}; /// /// fn main() { -/// let app = Application::new() +/// let app = App::new() /// .resource( /// "/", |r| r.method(http::Method::GET).f(|r| HttpResponse::Ok())) /// .finish(); @@ -79,7 +79,7 @@ impl Resource { /// use actix_web::*; /// /// fn main() { - /// let app = Application::new() + /// let app = App::new() /// .resource( /// "/", |r| r.route() /// .filter(pred::Any(pred::Get()).or(pred::Put())) @@ -149,7 +149,7 @@ impl Resource { /// Register a middleware /// - /// This is similar to `Application's` middlewares, but + /// This is similar to `App's` middlewares, but /// middlewares get invoked on resource level. pub fn middleware>(&mut self, mw: M) { Rc::get_mut(&mut self.middlewares).unwrap().push(Box::new(mw)); diff --git a/src/route.rs b/src/route.rs index 16399bd42..863a4ab55 100644 --- a/src/route.rs +++ b/src/route.rs @@ -62,7 +62,7 @@ impl Route { /// # extern crate actix_web; /// # use actix_web::*; /// # fn main() { - /// Application::new() + /// App::new() /// .resource("/path", |r| /// r.route() /// .filter(pred::Get()) @@ -109,7 +109,7 @@ impl Route { /// # extern crate actix_web; /// # extern crate futures; /// #[macro_use] extern crate serde_derive; - /// use actix_web::{Application, Path, Result, http}; + /// use actix_web::{App, Path, Result, http}; /// /// #[derive(Deserialize)] /// struct Info { @@ -122,7 +122,7 @@ impl Route { /// } /// /// fn main() { - /// let app = Application::new().resource( + /// let app = App::new().resource( /// "/{username}/index.html", // <- define path parameters /// |r| r.method(http::Method::GET).with(index)); // <- use `with` extractor /// } @@ -141,7 +141,7 @@ impl Route { /// # extern crate actix_web; /// # extern crate futures; /// #[macro_use] extern crate serde_derive; - /// use actix_web::{Application, Query, Path, Result, http}; + /// use actix_web::{App, Query, Path, Result, http}; /// /// #[derive(Deserialize)] /// struct PParam { @@ -159,7 +159,7 @@ impl Route { /// } /// /// fn main() { - /// let app = Application::new().resource( + /// let app = App::new().resource( /// "/{username}/index.html", // <- define path parameters /// |r| r.method(http::Method::GET).with2(index)); // <- use `with` extractor /// } diff --git a/src/server/mod.rs b/src/server/mod.rs index 3e5183751..fafcb9a27 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -38,13 +38,13 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536; /// # extern crate actix; /// # extern crate actix_web; /// use actix::*; -/// use actix_web::{server, Application, HttpResponse}; +/// use actix_web::{server, App, HttpResponse}; /// /// fn main() { /// let sys = actix::System::new("guide"); /// /// server::new( -/// || Application::new() +/// || App::new() /// .resource("/", |r| r.f(|_| HttpResponse::Ok()))) /// .bind("127.0.0.1:59080").unwrap() /// .start(); diff --git a/src/server/srv.rs b/src/server/srv.rs index 6aeda6b50..041021acf 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -268,7 +268,7 @@ impl HttpServer /// let sys = actix::System::new("example"); // <- create Actix system /// /// HttpServer::new( - /// || Application::new() + /// || App::new() /// .resource("/", |r| r.h(|_| HttpResponse::Ok()))) /// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0") /// .start(); @@ -326,7 +326,7 @@ impl HttpServer /// /// fn main() { /// HttpServer::new( - /// || Application::new() + /// || App::new() /// .resource("/", |r| r.h(|_| HttpResponse::Ok()))) /// .bind("127.0.0.1:0").expect("Can not bind to 127.0.0.1:0") /// .run(); diff --git a/src/test.rs b/src/test.rs index 7f385decd..742330915 100644 --- a/src/test.rs +++ b/src/test.rs @@ -23,7 +23,7 @@ use error::Error; use header::{Header, IntoHeaderValue}; use handler::{Handler, Responder, ReplyItem}; use middleware::Middleware; -use application::{Application, HttpApplication}; +use application::{App, HttpApplication}; use param::Params; use router::Router; use payload::Payload; @@ -327,12 +327,12 @@ impl TestServerBuilder { /// Test application helper for testing request handlers. pub struct TestApp { - app: Option>, + app: Option>, } impl TestApp { fn new(state: S) -> TestApp { - let app = Application::with_state(state); + let app = App::with_state(state); TestApp{app: Some(app)} } @@ -350,7 +350,7 @@ impl TestApp { } /// Register resource. This method is similar - /// to `Application::resource()` method. + /// to `App::resource()` method. pub fn resource(&mut self, path: &str, f: F) -> &mut TestApp where F: FnOnce(&mut Resource) + 'static { diff --git a/src/ws/mod.rs b/src/ws/mod.rs index 49e759511..c601236b6 100644 --- a/src/ws/mod.rs +++ b/src/ws/mod.rs @@ -37,7 +37,7 @@ //! } //! # //! # fn main() { -//! # Application::new() +//! # App::new() //! # .resource("/ws/", |r| r.f(ws_index)) // <- register websocket route //! # .finish(); //! # } diff --git a/tests/test_server.rs b/tests/test_server.rs index bc1e69c38..a13fc2f85 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -64,7 +64,7 @@ fn test_start() { thread::spawn(move || { let sys = System::new("test"); let srv = HttpServer::new( - || vec![Application::new() + || vec![App::new() .resource( "/", |r| r.method(http::Method::GET) .f(|_|HttpResponse::Ok()))]); @@ -109,7 +109,7 @@ fn test_shutdown() { thread::spawn(move || { let sys = System::new("test"); let srv = HttpServer::new( - || vec![Application::new() + || vec![App::new() .resource( "/", |r| r.method(http::Method::GET).f(|_| HttpResponse::Ok()))]); @@ -749,7 +749,7 @@ fn test_h2() { #[test] fn test_application() { let mut srv = test::TestServer::with_factory( - || Application::new().resource("/", |r| r.f(|_| HttpResponse::Ok()))); + || App::new().resource("/", |r| r.f(|_| HttpResponse::Ok()))); let request = srv.get().finish().unwrap(); let response = srv.execute(request.send()).unwrap();