From 29adc205815c7c215751c9f17fa7874f5ecccf0e Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 26 Dec 2017 19:59:41 -0800 Subject: [PATCH] rename module --- examples/basic.rs | 8 ++-- examples/diesel/src/main.rs | 2 +- examples/json/src/main.rs | 2 +- examples/multipart/src/main.rs | 2 +- examples/state.rs | 2 +- examples/template_tera/src/main.rs | 2 +- examples/tls/src/main.rs | 2 +- examples/websocket.rs | 2 +- guide/src/qs_10.md | 38 +++++++++---------- guide/src/qs_3.md | 8 ++-- src/application.rs | 2 +- src/lib.rs | 2 +- .../defaultheaders.rs | 4 +- src/{middlewares => middleware}/logger.rs | 6 +-- src/{middlewares => middleware}/mod.rs | 0 src/{middlewares => middleware}/session.rs | 14 +++---- src/pipeline.rs | 2 +- src/test/mod.rs | 2 +- tests/test_server.rs | 14 +++---- 19 files changed, 57 insertions(+), 57 deletions(-) rename src/{middlewares => middleware}/defaultheaders.rs (97%) rename src/{middlewares => middleware}/logger.rs (98%) rename src/{middlewares => middleware}/mod.rs (100%) rename src/{middlewares => middleware}/session.rs (97%) diff --git a/examples/basic.rs b/examples/basic.rs index 9beecbcde..7328a5a96 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -8,7 +8,7 @@ extern crate futures; use futures::Stream; use actix_web::*; -use actix_web::middlewares::RequestSession; +use actix_web::middleware::RequestSession; use futures::future::{FutureResult, result}; /// simple handler @@ -60,10 +60,10 @@ fn main() { HttpServer::new( || Application::new() // enable logger - .middleware(middlewares::Logger::default()) + .middleware(middleware::Logger::default()) // cookie session middleware - .middleware(middlewares::SessionStorage::new( - middlewares::CookieSessionBackend::build(&[0; 32]) + .middleware(middleware::SessionStorage::new( + middleware::CookieSessionBackend::build(&[0; 32]) .secure(false) .finish() )) diff --git a/examples/diesel/src/main.rs b/examples/diesel/src/main.rs index c05857c1a..350a9ee5a 100644 --- a/examples/diesel/src/main.rs +++ b/examples/diesel/src/main.rs @@ -62,7 +62,7 @@ fn main() { HttpServer::new(move || { Application::with_state(State{db: addr.clone()}) // enable logger - .middleware(middlewares::Logger::default()) + .middleware(middleware::Logger::default()) .resource("/{name}", |r| r.method(Method::GET).a(index))}) .bind("127.0.0.1:8080").unwrap() .start(); diff --git a/examples/json/src/main.rs b/examples/json/src/main.rs index 9bc8bebcd..c49bfa152 100644 --- a/examples/json/src/main.rs +++ b/examples/json/src/main.rs @@ -67,7 +67,7 @@ fn main() { HttpServer::new(|| { Application::new() // enable logger - .middleware(middlewares::Logger::default()) + .middleware(middleware::Logger::default()) .resource("/manual", |r| r.method(Method::POST).f(index_manual)) .resource("/", |r| r.method(Method::POST).f(index))}) .bind("127.0.0.1:8080").unwrap() diff --git a/examples/multipart/src/main.rs b/examples/multipart/src/main.rs index 41204bef0..1af329c2f 100644 --- a/examples/multipart/src/main.rs +++ b/examples/multipart/src/main.rs @@ -48,7 +48,7 @@ fn main() { HttpServer::new( || Application::new() - .middleware(middlewares::Logger::default()) // <- logger + .middleware(middleware::Logger::default()) // <- logger .resource("/multipart", |r| r.method(Method::POST).a(index))) .bind("127.0.0.1:8080").unwrap() .start(); diff --git a/examples/state.rs b/examples/state.rs index 0a10b77bd..dfa201f0c 100644 --- a/examples/state.rs +++ b/examples/state.rs @@ -63,7 +63,7 @@ fn main() { HttpServer::new( || Application::with_state(AppState{counter: Cell::new(0)}) // enable logger - .middleware(middlewares::Logger::default()) + .middleware(middleware::Logger::default()) // websocket route .resource( "/ws/", |r| diff --git a/examples/template_tera/src/main.rs b/examples/template_tera/src/main.rs index 86b37e0d6..1925ad4e2 100644 --- a/examples/template_tera/src/main.rs +++ b/examples/template_tera/src/main.rs @@ -35,7 +35,7 @@ fn main() { Application::with_state(State{template: tera}) // enable logger - .middleware(middlewares::Logger::default()) + .middleware(middleware::Logger::default()) .resource("/", |r| r.method(Method::GET).f(index))}) .bind("127.0.0.1:8080").unwrap() .start(); diff --git a/examples/tls/src/main.rs b/examples/tls/src/main.rs index 4ab0cbca2..8dce633e6 100644 --- a/examples/tls/src/main.rs +++ b/examples/tls/src/main.rs @@ -32,7 +32,7 @@ fn main() { HttpServer::new( || Application::new() // enable logger - .middleware(middlewares::Logger::default()) + .middleware(middleware::Logger::default()) // register simple handler, handle all methods .resource("/index.html", |r| r.f(index)) // with path parameters diff --git a/examples/websocket.rs b/examples/websocket.rs index 4b416b541..2a80add1b 100644 --- a/examples/websocket.rs +++ b/examples/websocket.rs @@ -63,7 +63,7 @@ fn main() { HttpServer::new( || Application::new() // enable logger - .middleware(middlewares::Logger::default()) + .middleware(middleware::Logger::default()) // websocket route .resource("/ws/", |r| r.method(Method::GET).f(ws_index)) // static files diff --git a/guide/src/qs_10.md b/guide/src/qs_10.md index 435e2966e..89bf8c6d3 100644 --- a/guide/src/qs_10.md +++ b/guide/src/qs_10.md @@ -11,8 +11,8 @@ Typically middlewares involves in following actions: * Modify application state * Access external services (redis, logging, sessions) -Middlewares are registered for each application and get executed in same order as -registraton order. In general, *middleware* is a type that implements +Middlewares are registered for each application and get executed in same order as +registraton order. In general, *middleware* is a type that implements [*Middleware trait*](../actix_web/middlewares/trait.Middleware.html). Each method in this trait has default implementation. Each method can return result immidietly or *future* object. @@ -24,7 +24,7 @@ Here is example of simple middleware that adds request and response headers: # extern crate actix_web; use http::{header, HttpTryFrom}; use actix_web::*; -use actix_web::middlewares::{Middleware, Started, Response}; +use actix_web::middleware::{Middleware, Started, Response}; struct Headers; // <- Our middleware @@ -68,7 +68,7 @@ Logging middleware has to be registered for each application. ### Usage -Create `Logger` middlewares with the specified `format`. +Create `Logger` middleware with the specified `format`. Default `Logger` could be created with `default` method, it uses the default format: ```ignore @@ -77,7 +77,7 @@ Default `Logger` could be created with `default` method, it uses the default for ```rust # extern crate actix_web; use actix_web::Application; -use actix_web::middlewares::Logger; +use actix_web::middleware::Logger; fn main() { Application::new() @@ -90,8 +90,8 @@ fn main() { Here is example of default logging format: ``` -INFO:actix_web::middlewares::logger: 127.0.0.1:59934 [02/Dec/2017:00:21:43 -0800] "GET / HTTP/1.1" 302 0 "-" "curl/7.54.0" 0.000397 -INFO:actix_web::middlewares::logger: 127.0.0.1:59947 [02/Dec/2017:00:22:40 -0800] "GET /index.html HTTP/1.1" 200 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0" 0.000646 +INFO:actix_web::middleware::logger: 127.0.0.1:59934 [02/Dec/2017:00:21:43 -0800] "GET / HTTP/1.1" 302 0 "-" "curl/7.54.0" 0.000397 +INFO:actix_web::middleware::logger: 127.0.0.1:59947 [02/Dec/2017:00:22:40 -0800] "GET /index.html HTTP/1.1" 200 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0" 0.000646 ``` ### Format @@ -134,7 +134,7 @@ use actix_web::*; fn main() { let app = Application::new() .middleware( - middlewares::DefaultHeaders::build() + middleware::DefaultHeaders::build() .header("X-Version", "0.2") .finish()) .resource("/test", |r| { @@ -148,14 +148,14 @@ fn main() { ## User sessions Actix provides general solution for session management. -[*Session storage*](../actix_web/middlewares/struct.SessionStorage.html) middleare can be +[*Session storage*](../actix_web/middleware/struct.SessionStorage.html) middleare can be use with different backend types to store session data in different backends. By default only cookie session backend is implemented. Other backend implementations could be added later. -[*Cookie session backend*](../actix_web/middlewares/struct.CookieSessionBackend.html) -uses signed cookies as session storage. *Cookie session backend* creates sessions which -are limited to storing fewer than 4000 bytes of data (as the payload must fit into a +[*Cookie session backend*](../actix_web/middleware/struct.CookieSessionBackend.html) +uses signed cookies as session storage. *Cookie session backend* creates sessions which +are limited to storing fewer than 4000 bytes of data (as the payload must fit into a single cookie). Internal server error get generated if session contains more than 4000 bytes. You need to pass a random value to the constructor of *CookieSessionBackend*. @@ -163,19 +163,19 @@ This is private key for cookie session. When this value is changed, all session Note that whatever you write into your session is visible by the user (but not modifiable). In general case, you cretate -[*Session storage*](../actix_web/middlewares/struct.SessionStorage.html) middleware -and initializes it with specific backend implementation, like *CookieSessionBackend*. +[*Session storage*](../actix_web/middleware/struct.SessionStorage.html) middleware +and initializes it with specific backend implementation, like *CookieSessionBackend*. To access session data -[*HttpRequest::session()*](../actix_web/middlewares/trait.RequestSession.html#tymethod.session) +[*HttpRequest::session()*](../actix_web/middleware/trait.RequestSession.html#tymethod.session) method has to be used. This method returns -[*Session*](../actix_web/middlewares/struct.Session.html) object, which allows to get or set +[*Session*](../actix_web/middleware/struct.Session.html) object, which allows to get or set session data. ```rust # extern crate actix; # extern crate actix_web; use actix_web::*; -use actix_web::middlewares::{RequestSession, SessionStorage, CookieSessionBackend}; +use actix_web::middleware::{RequestSession, SessionStorage, CookieSessionBackend}; fn index(mut req: HttpRequest) -> Result<&'static str> { // access session data @@ -193,11 +193,11 @@ fn main() { # let sys = actix::System::new("basic-example"); HttpServer::new( || Application::new() - .middleware(SessionStorage::new( // <- create session middlewares + .middleware(SessionStorage::new( // <- create session middleware CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend .secure(false) .finish() - ))) + ))) .bind("127.0.0.1:59880").unwrap() .start(); # actix::Arbiter::system().send(actix::msgs::SystemExit(0)); diff --git a/guide/src/qs_3.md b/guide/src/qs_3.md index 40c6dfb95..38383084b 100644 --- a/guide/src/qs_3.md +++ b/guide/src/qs_3.md @@ -62,16 +62,16 @@ All `/app1` requests route to first application, `/app2` to second and then all Application state is shared with all routes and resources within same application. State could be accessed with `HttpRequest::state()` method as a read-only item but interior mutability pattern with `RefCell` could be used to archive state mutability. -State could be accessed with `HttpContext::state()` in case of http actor. +State could be accessed with `HttpContext::state()` in case of http actor. State also available to route matching predicates and middlewares. Let's write simple application that uses shared state. We are going to store requests count -in the state: - +in the state: + ```rust # extern crate actix; # extern crate actix_web; -# +# use actix_web::*; use std::cell::Cell; diff --git a/src/application.rs b/src/application.rs index 1de0ff5b6..21de726e7 100644 --- a/src/application.rs +++ b/src/application.rs @@ -7,7 +7,7 @@ use resource::Resource; use httprequest::HttpRequest; use channel::{HttpHandler, IntoHttpHandler, HttpHandlerTask}; use pipeline::Pipeline; -use middlewares::Middleware; +use middleware::Middleware; use server::ServerSettings; /// Application diff --git a/src/lib.rs b/src/lib.rs index e8e93eb57..2689bc111 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -115,7 +115,7 @@ pub mod ws; pub mod error; pub mod httpcodes; pub mod multipart; -pub mod middlewares; +pub mod middleware; pub mod pred; pub mod test; pub mod payload; diff --git a/src/middlewares/defaultheaders.rs b/src/middleware/defaultheaders.rs similarity index 97% rename from src/middlewares/defaultheaders.rs rename to src/middleware/defaultheaders.rs index 6968c8978..a013b7a57 100644 --- a/src/middlewares/defaultheaders.rs +++ b/src/middleware/defaultheaders.rs @@ -4,7 +4,7 @@ use http::header::{HeaderName, HeaderValue, CONTENT_TYPE}; use httprequest::HttpRequest; use httpresponse::HttpResponse; -use middlewares::{Response, Middleware}; +use middleware::{Response, Middleware}; /// `Middleware` for setting default response headers. /// @@ -17,7 +17,7 @@ use middlewares::{Response, Middleware}; /// fn main() { /// let app = Application::new() /// .middleware( -/// middlewares::DefaultHeaders::build() +/// middleware::DefaultHeaders::build() /// .header("X-Version", "0.2") /// .finish()) /// .resource("/test", |r| { diff --git a/src/middlewares/logger.rs b/src/middleware/logger.rs similarity index 98% rename from src/middlewares/logger.rs rename to src/middleware/logger.rs index 507908148..e498ad4c9 100644 --- a/src/middlewares/logger.rs +++ b/src/middleware/logger.rs @@ -9,13 +9,13 @@ use regex::Regex; use httprequest::HttpRequest; use httpresponse::HttpResponse; -use middlewares::{Middleware, Started, Finished}; +use middleware::{Middleware, Started, Finished}; /// `Middleware` for logging request and response info to the terminal. /// /// ## Usage /// -/// Create `Logger` middlewares with the specified `format`. +/// Create `Logger` middleware with the specified `format`. /// Default `Logger` could be created with `default` method, it uses the default format: /// /// ```ignore @@ -24,7 +24,7 @@ use middlewares::{Middleware, Started, Finished}; /// ```rust /// # extern crate actix_web; /// use actix_web::Application; -/// use actix_web::middlewares::Logger; +/// use actix_web::middleware::Logger; /// /// fn main() { /// let app = Application::new() diff --git a/src/middlewares/mod.rs b/src/middleware/mod.rs similarity index 100% rename from src/middlewares/mod.rs rename to src/middleware/mod.rs diff --git a/src/middlewares/session.rs b/src/middleware/session.rs similarity index 97% rename from src/middlewares/session.rs rename to src/middleware/session.rs index 6edba1983..8ac068888 100644 --- a/src/middlewares/session.rs +++ b/src/middleware/session.rs @@ -17,13 +17,13 @@ use futures::future::{FutureResult, ok as FutOk, err as FutErr}; use error::{Result, Error, ResponseError}; use httprequest::HttpRequest; use httpresponse::HttpResponse; -use middlewares::{Middleware, Started, Response}; +use middleware::{Middleware, Started, Response}; /// The helper trait to obtain your session data from a request. /// /// ```rust /// use actix_web::*; -/// use actix_web::middlewares::RequestSession; +/// use actix_web::middleware::RequestSession; /// /// fn index(mut req: HttpRequest) -> Result<&'static str> { /// // access session data @@ -62,7 +62,7 @@ impl RequestSession for HttpRequest { /// /// ```rust /// use actix_web::*; -/// use actix_web::middlewares::RequestSession; +/// use actix_web::middleware::RequestSession; /// /// fn index(mut req: HttpRequest) -> Result<&'static str> { /// // access session data @@ -118,12 +118,12 @@ unsafe impl Sync for SessionImplBox {} /// ```rust /// # extern crate actix; /// # extern crate actix_web; -/// # use actix_web::middlewares::{SessionStorage, CookieSessionBackend}; +/// # use actix_web::middleware::{SessionStorage, CookieSessionBackend}; /// use actix_web::*; /// /// fn main() { /// let app = Application::new().middleware( -/// SessionStorage::new( // <- create session middlewares +/// SessionStorage::new( // <- create session middleware /// CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend /// .secure(false) /// .finish()) @@ -358,7 +358,7 @@ impl CookieSessionBackend { /// # Example /// /// ``` - /// use actix_web::middlewares::CookieSessionBackend; + /// use actix_web::middleware::CookieSessionBackend; /// /// let backend = CookieSessionBackend::build(&[0; 32]).finish(); /// ``` @@ -396,7 +396,7 @@ impl SessionBackend for CookieSessionBackend { /// ```rust /// # extern crate actix_web; /// -/// use actix_web::middlewares::CookieSessionBackend; +/// use actix_web::middleware::CookieSessionBackend; /// /// # fn main() { /// let backend: CookieSessionBackend = CookieSessionBackend::build(&[0; 32]) diff --git a/src/pipeline.rs b/src/pipeline.rs index cc17d2f33..d4a8edd84 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -13,7 +13,7 @@ use handler::{Reply, ReplyItem}; use h1writer::{Writer, WriterState}; use httprequest::HttpRequest; use httpresponse::HttpResponse; -use middlewares::{Middleware, Finished, Started, Response}; +use middleware::{Middleware, Finished, Started, Response}; type Handler = FnMut(HttpRequest) -> Reply; pub(crate) type PipelineHandler<'a, S> = &'a mut FnMut(HttpRequest) -> Reply; diff --git a/src/test/mod.rs b/src/test/mod.rs index 0d3c596f3..1d388eda8 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -18,7 +18,7 @@ use error::Error; use server::HttpServer; use handler::{Handler, Responder, ReplyItem}; use channel::{HttpHandler, IntoHttpHandler}; -use middlewares::Middleware; +use middleware::Middleware; use application::{Application, HttpApplication}; use param::Params; use router::Router; diff --git a/tests/test_server.rs b/tests/test_server.rs index d148e9ef8..c5e166713 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -27,20 +27,20 @@ struct MiddlewareTest { finish: Arc, } -impl middlewares::Middleware for MiddlewareTest { - fn start(&self, _: &mut HttpRequest) -> middlewares::Started { +impl middleware::Middleware for MiddlewareTest { + fn start(&self, _: &mut HttpRequest) -> middleware::Started { self.start.store(self.start.load(Ordering::Relaxed) + 1, Ordering::Relaxed); - middlewares::Started::Done + middleware::Started::Done } - fn response(&self, _: &mut HttpRequest, resp: HttpResponse) -> middlewares::Response { + fn response(&self, _: &mut HttpRequest, resp: HttpResponse) -> middleware::Response { self.response.store(self.response.load(Ordering::Relaxed) + 1, Ordering::Relaxed); - middlewares::Response::Done(resp) + middleware::Response::Done(resp) } - fn finish(&self, _: &mut HttpRequest, _: &HttpResponse) -> middlewares::Finished { + fn finish(&self, _: &mut HttpRequest, _: &HttpResponse) -> middleware::Finished { self.finish.store(self.finish.load(Ordering::Relaxed) + 1, Ordering::Relaxed); - middlewares::Finished::Done + middleware::Finished::Done } }