1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-23 16:40:37 +00: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 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()
))

View file

@ -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();

View file

@ -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()

View file

@ -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();

View file

@ -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|

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -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));

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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| {

View file

@ -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()

View file

@ -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<S> SessionBackend<S> 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])

View file

@ -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<S> = 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 handler::{Handler, Responder, ReplyItem};
use channel::{HttpHandler, IntoHttpHandler};
use middlewares::Middleware;
use middleware::Middleware;
use application::{Application, HttpApplication};
use param::Params;
use router::Router;

View file

@ -27,20 +27,20 @@ struct MiddlewareTest {
finish: Arc<AtomicUsize>,
}
impl<S> middlewares::Middleware<S> for MiddlewareTest {
fn start(&self, _: &mut HttpRequest<S>) -> middlewares::Started {
impl<S> middleware::Middleware<S> for MiddlewareTest {
fn start(&self, _: &mut HttpRequest<S>) -> middleware::Started {
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);
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);
middlewares::Finished::Done
middleware::Finished::Done
}
}