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:
parent
743235b8fd
commit
29adc20581
19 changed files with 57 additions and 57 deletions
|
@ -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()
|
||||
))
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,12 +148,12 @@ 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)
|
||||
[*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.
|
||||
|
@ -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
|
||||
[*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,7 +193,7 @@ 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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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| {
|
|
@ -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()
|
|
@ -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])
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue