1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-18 05:41:50 +01:00

rename module

This commit is contained in:
Nikolay Kim 2017-12-26 19:59:41 -08:00
parent 743235b8fd
commit 29adc20581
19 changed files with 57 additions and 57 deletions

View File

@ -8,7 +8,7 @@ extern crate futures;
use futures::Stream; use futures::Stream;
use actix_web::*; use actix_web::*;
use actix_web::middlewares::RequestSession; use actix_web::middleware::RequestSession;
use futures::future::{FutureResult, result}; use futures::future::{FutureResult, result};
/// simple handler /// simple handler
@ -60,10 +60,10 @@ fn main() {
HttpServer::new( HttpServer::new(
|| Application::new() || Application::new()
// enable logger // enable logger
.middleware(middlewares::Logger::default()) .middleware(middleware::Logger::default())
// cookie session middleware // cookie session middleware
.middleware(middlewares::SessionStorage::new( .middleware(middleware::SessionStorage::new(
middlewares::CookieSessionBackend::build(&[0; 32]) middleware::CookieSessionBackend::build(&[0; 32])
.secure(false) .secure(false)
.finish() .finish()
)) ))

View File

@ -62,7 +62,7 @@ fn main() {
HttpServer::new(move || { HttpServer::new(move || {
Application::with_state(State{db: addr.clone()}) Application::with_state(State{db: addr.clone()})
// enable logger // enable logger
.middleware(middlewares::Logger::default()) .middleware(middleware::Logger::default())
.resource("/{name}", |r| r.method(Method::GET).a(index))}) .resource("/{name}", |r| r.method(Method::GET).a(index))})
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();

View File

@ -67,7 +67,7 @@ fn main() {
HttpServer::new(|| { HttpServer::new(|| {
Application::new() Application::new()
// enable logger // enable logger
.middleware(middlewares::Logger::default()) .middleware(middleware::Logger::default())
.resource("/manual", |r| r.method(Method::POST).f(index_manual)) .resource("/manual", |r| r.method(Method::POST).f(index_manual))
.resource("/", |r| r.method(Method::POST).f(index))}) .resource("/", |r| r.method(Method::POST).f(index))})
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()

View File

@ -48,7 +48,7 @@ fn main() {
HttpServer::new( HttpServer::new(
|| Application::new() || Application::new()
.middleware(middlewares::Logger::default()) // <- logger .middleware(middleware::Logger::default()) // <- logger
.resource("/multipart", |r| r.method(Method::POST).a(index))) .resource("/multipart", |r| r.method(Method::POST).a(index)))
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();

View File

@ -63,7 +63,7 @@ fn main() {
HttpServer::new( HttpServer::new(
|| Application::with_state(AppState{counter: Cell::new(0)}) || Application::with_state(AppState{counter: Cell::new(0)})
// enable logger // enable logger
.middleware(middlewares::Logger::default()) .middleware(middleware::Logger::default())
// websocket route // websocket route
.resource( .resource(
"/ws/", |r| "/ws/", |r|

View File

@ -35,7 +35,7 @@ fn main() {
Application::with_state(State{template: tera}) Application::with_state(State{template: tera})
// enable logger // enable logger
.middleware(middlewares::Logger::default()) .middleware(middleware::Logger::default())
.resource("/", |r| r.method(Method::GET).f(index))}) .resource("/", |r| r.method(Method::GET).f(index))})
.bind("127.0.0.1:8080").unwrap() .bind("127.0.0.1:8080").unwrap()
.start(); .start();

View File

@ -32,7 +32,7 @@ fn main() {
HttpServer::new( HttpServer::new(
|| Application::new() || Application::new()
// enable logger // enable logger
.middleware(middlewares::Logger::default()) .middleware(middleware::Logger::default())
// register simple handler, handle all methods // register simple handler, handle all methods
.resource("/index.html", |r| r.f(index)) .resource("/index.html", |r| r.f(index))
// with path parameters // with path parameters

View File

@ -63,7 +63,7 @@ fn main() {
HttpServer::new( HttpServer::new(
|| Application::new() || Application::new()
// enable logger // enable logger
.middleware(middlewares::Logger::default()) .middleware(middleware::Logger::default())
// websocket route // websocket route
.resource("/ws/", |r| r.method(Method::GET).f(ws_index)) .resource("/ws/", |r| r.method(Method::GET).f(ws_index))
// static files // static files

View File

@ -24,7 +24,7 @@ Here is example of simple middleware that adds request and response headers:
# extern crate actix_web; # extern crate actix_web;
use http::{header, HttpTryFrom}; use http::{header, HttpTryFrom};
use actix_web::*; use actix_web::*;
use actix_web::middlewares::{Middleware, Started, Response}; use actix_web::middleware::{Middleware, Started, Response};
struct Headers; // <- Our middleware struct Headers; // <- Our middleware
@ -68,7 +68,7 @@ Logging middleware has to be registered for each application.
### Usage ### 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: Default `Logger` could be created with `default` method, it uses the default format:
```ignore ```ignore
@ -77,7 +77,7 @@ Default `Logger` could be created with `default` method, it uses the default for
```rust ```rust
# extern crate actix_web; # extern crate actix_web;
use actix_web::Application; use actix_web::Application;
use actix_web::middlewares::Logger; use actix_web::middleware::Logger;
fn main() { fn main() {
Application::new() Application::new()
@ -90,8 +90,8 @@ fn main() {
Here is example of default logging format: 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::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::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: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 ### Format
@ -134,7 +134,7 @@ use actix_web::*;
fn main() { fn main() {
let app = Application::new() let app = Application::new()
.middleware( .middleware(
middlewares::DefaultHeaders::build() middleware::DefaultHeaders::build()
.header("X-Version", "0.2") .header("X-Version", "0.2")
.finish()) .finish())
.resource("/test", |r| { .resource("/test", |r| {
@ -148,12 +148,12 @@ fn main() {
## User sessions ## User sessions
Actix provides general solution for session management. 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. use with different backend types to store session data in different backends.
By default only cookie session backend is implemented. Other backend implementations By default only cookie session backend is implemented. Other backend implementations
could be added later. could be added later.
[*Cookie session backend*](../actix_web/middlewares/struct.CookieSessionBackend.html) [*Cookie session backend*](../actix_web/middleware/struct.CookieSessionBackend.html)
uses signed cookies as session storage. *Cookie session backend* creates sessions which 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 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. single cookie). Internal server error get generated if session contains more than 4000 bytes.
@ -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). Note that whatever you write into your session is visible by the user (but not modifiable).
In general case, you cretate In general case, you cretate
[*Session storage*](../actix_web/middlewares/struct.SessionStorage.html) middleware [*Session storage*](../actix_web/middleware/struct.SessionStorage.html) middleware
and initializes it with specific backend implementation, like *CookieSessionBackend*. and initializes it with specific backend implementation, like *CookieSessionBackend*.
To access session data 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 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. session data.
```rust ```rust
# extern crate actix; # extern crate actix;
# extern crate actix_web; # extern crate actix_web;
use 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> { fn index(mut req: HttpRequest) -> Result<&'static str> {
// access session data // access session data
@ -193,7 +193,7 @@ fn main() {
# let sys = actix::System::new("basic-example"); # let sys = actix::System::new("basic-example");
HttpServer::new( HttpServer::new(
|| Application::new() || Application::new()
.middleware(SessionStorage::new( // <- create session middlewares .middleware(SessionStorage::new( // <- create session middleware
CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend
.secure(false) .secure(false)
.finish() .finish()

View File

@ -7,7 +7,7 @@ use resource::Resource;
use httprequest::HttpRequest; use httprequest::HttpRequest;
use channel::{HttpHandler, IntoHttpHandler, HttpHandlerTask}; use channel::{HttpHandler, IntoHttpHandler, HttpHandlerTask};
use pipeline::Pipeline; use pipeline::Pipeline;
use middlewares::Middleware; use middleware::Middleware;
use server::ServerSettings; use server::ServerSettings;
/// Application /// Application

View File

@ -115,7 +115,7 @@ pub mod ws;
pub mod error; pub mod error;
pub mod httpcodes; pub mod httpcodes;
pub mod multipart; pub mod multipart;
pub mod middlewares; pub mod middleware;
pub mod pred; pub mod pred;
pub mod test; pub mod test;
pub mod payload; pub mod payload;

View File

@ -4,7 +4,7 @@ use http::header::{HeaderName, HeaderValue, CONTENT_TYPE};
use httprequest::HttpRequest; use httprequest::HttpRequest;
use httpresponse::HttpResponse; use httpresponse::HttpResponse;
use middlewares::{Response, Middleware}; use middleware::{Response, Middleware};
/// `Middleware` for setting default response headers. /// `Middleware` for setting default response headers.
/// ///
@ -17,7 +17,7 @@ use middlewares::{Response, Middleware};
/// fn main() { /// fn main() {
/// let app = Application::new() /// let app = Application::new()
/// .middleware( /// .middleware(
/// middlewares::DefaultHeaders::build() /// middleware::DefaultHeaders::build()
/// .header("X-Version", "0.2") /// .header("X-Version", "0.2")
/// .finish()) /// .finish())
/// .resource("/test", |r| { /// .resource("/test", |r| {

View File

@ -9,13 +9,13 @@ use regex::Regex;
use httprequest::HttpRequest; use httprequest::HttpRequest;
use httpresponse::HttpResponse; use httpresponse::HttpResponse;
use middlewares::{Middleware, Started, Finished}; use middleware::{Middleware, Started, Finished};
/// `Middleware` for logging request and response info to the terminal. /// `Middleware` for logging request and response info to the terminal.
/// ///
/// ## Usage /// ## 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: /// Default `Logger` could be created with `default` method, it uses the default format:
/// ///
/// ```ignore /// ```ignore
@ -24,7 +24,7 @@ use middlewares::{Middleware, Started, Finished};
/// ```rust /// ```rust
/// # extern crate actix_web; /// # extern crate actix_web;
/// use actix_web::Application; /// use actix_web::Application;
/// use actix_web::middlewares::Logger; /// use actix_web::middleware::Logger;
/// ///
/// fn main() { /// fn main() {
/// let app = Application::new() /// let app = Application::new()

View File

@ -17,13 +17,13 @@ use futures::future::{FutureResult, ok as FutOk, err as FutErr};
use error::{Result, Error, ResponseError}; use error::{Result, Error, ResponseError};
use httprequest::HttpRequest; use httprequest::HttpRequest;
use httpresponse::HttpResponse; use httpresponse::HttpResponse;
use middlewares::{Middleware, Started, Response}; use middleware::{Middleware, Started, Response};
/// The helper trait to obtain your session data from a request. /// The helper trait to obtain your session data from a request.
/// ///
/// ```rust /// ```rust
/// use actix_web::*; /// use actix_web::*;
/// use actix_web::middlewares::RequestSession; /// use actix_web::middleware::RequestSession;
/// ///
/// fn index(mut req: HttpRequest) -> Result<&'static str> { /// fn index(mut req: HttpRequest) -> Result<&'static str> {
/// // access session data /// // access session data
@ -62,7 +62,7 @@ impl RequestSession for HttpRequest {
/// ///
/// ```rust /// ```rust
/// use actix_web::*; /// use actix_web::*;
/// use actix_web::middlewares::RequestSession; /// use actix_web::middleware::RequestSession;
/// ///
/// fn index(mut req: HttpRequest) -> Result<&'static str> { /// fn index(mut req: HttpRequest) -> Result<&'static str> {
/// // access session data /// // access session data
@ -118,12 +118,12 @@ unsafe impl Sync for SessionImplBox {}
/// ```rust /// ```rust
/// # extern crate actix; /// # extern crate actix;
/// # extern crate actix_web; /// # extern crate actix_web;
/// # use actix_web::middlewares::{SessionStorage, CookieSessionBackend}; /// # use actix_web::middleware::{SessionStorage, CookieSessionBackend};
/// use actix_web::*; /// use actix_web::*;
/// ///
/// fn main() { /// fn main() {
/// let app = Application::new().middleware( /// let app = Application::new().middleware(
/// SessionStorage::new( // <- create session middlewares /// SessionStorage::new( // <- create session middleware
/// CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend /// CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend
/// .secure(false) /// .secure(false)
/// .finish()) /// .finish())
@ -358,7 +358,7 @@ impl CookieSessionBackend {
/// # Example /// # Example
/// ///
/// ``` /// ```
/// use actix_web::middlewares::CookieSessionBackend; /// use actix_web::middleware::CookieSessionBackend;
/// ///
/// let backend = CookieSessionBackend::build(&[0; 32]).finish(); /// let backend = CookieSessionBackend::build(&[0; 32]).finish();
/// ``` /// ```
@ -396,7 +396,7 @@ impl<S> SessionBackend<S> for CookieSessionBackend {
/// ```rust /// ```rust
/// # extern crate actix_web; /// # extern crate actix_web;
/// ///
/// use actix_web::middlewares::CookieSessionBackend; /// use actix_web::middleware::CookieSessionBackend;
/// ///
/// # fn main() { /// # fn main() {
/// let backend: CookieSessionBackend = CookieSessionBackend::build(&[0; 32]) /// let backend: CookieSessionBackend = CookieSessionBackend::build(&[0; 32])

View File

@ -13,7 +13,7 @@ use handler::{Reply, ReplyItem};
use h1writer::{Writer, WriterState}; use h1writer::{Writer, WriterState};
use httprequest::HttpRequest; use httprequest::HttpRequest;
use httpresponse::HttpResponse; use httpresponse::HttpResponse;
use middlewares::{Middleware, Finished, Started, Response}; use middleware::{Middleware, Finished, Started, Response};
type Handler<S> = FnMut(HttpRequest<S>) -> Reply; type Handler<S> = FnMut(HttpRequest<S>) -> Reply;
pub(crate) type PipelineHandler<'a, S> = &'a mut FnMut(HttpRequest<S>) -> Reply; pub(crate) type PipelineHandler<'a, S> = &'a mut FnMut(HttpRequest<S>) -> Reply;

View File

@ -18,7 +18,7 @@ use error::Error;
use server::HttpServer; use server::HttpServer;
use handler::{Handler, Responder, ReplyItem}; use handler::{Handler, Responder, ReplyItem};
use channel::{HttpHandler, IntoHttpHandler}; use channel::{HttpHandler, IntoHttpHandler};
use middlewares::Middleware; use middleware::Middleware;
use application::{Application, HttpApplication}; use application::{Application, HttpApplication};
use param::Params; use param::Params;
use router::Router; use router::Router;

View File

@ -27,20 +27,20 @@ struct MiddlewareTest {
finish: Arc<AtomicUsize>, finish: Arc<AtomicUsize>,
} }
impl<S> middlewares::Middleware<S> for MiddlewareTest { impl<S> middleware::Middleware<S> for MiddlewareTest {
fn start(&self, _: &mut HttpRequest<S>) -> middlewares::Started { fn start(&self, _: &mut HttpRequest<S>) -> middleware::Started {
self.start.store(self.start.load(Ordering::Relaxed) + 1, Ordering::Relaxed); self.start.store(self.start.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
middlewares::Started::Done middleware::Started::Done
} }
fn response(&self, _: &mut HttpRequest<S>, resp: HttpResponse) -> middlewares::Response { fn response(&self, _: &mut HttpRequest<S>, resp: HttpResponse) -> middleware::Response {
self.response.store(self.response.load(Ordering::Relaxed) + 1, Ordering::Relaxed); self.response.store(self.response.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
middlewares::Response::Done(resp) middleware::Response::Done(resp)
} }
fn finish(&self, _: &mut HttpRequest<S>, _: &HttpResponse) -> middlewares::Finished { fn finish(&self, _: &mut HttpRequest<S>, _: &HttpResponse) -> middleware::Finished {
self.finish.store(self.finish.load(Ordering::Relaxed) + 1, Ordering::Relaxed); self.finish.store(self.finish.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
middlewares::Finished::Done middleware::Finished::Done
} }
} }