mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
do not re-export HttpServer from server module
This commit is contained in:
parent
12586db15c
commit
2dafd9c681
@ -8,8 +8,8 @@ extern crate futures;
|
|||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
|
|
||||||
use std::{io, env};
|
use std::{io, env};
|
||||||
use actix_web::{error, fs, pred,
|
use actix_web::{error, fs, pred, server,
|
||||||
App, HttpRequest, HttpResponse, HttpServer, Result, Error};
|
App, HttpRequest, HttpResponse, Result, Error};
|
||||||
use actix_web::http::{Method, StatusCode};
|
use actix_web::http::{Method, StatusCode};
|
||||||
use actix_web::middleware::{self, RequestSession};
|
use actix_web::middleware::{self, RequestSession};
|
||||||
use futures::future::{FutureResult, result};
|
use futures::future::{FutureResult, result};
|
||||||
@ -99,7 +99,7 @@ fn main() {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("basic-example");
|
let sys = actix::System::new("basic-example");
|
||||||
|
|
||||||
let addr = HttpServer::new(
|
let addr = server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
|
@ -4,9 +4,10 @@ extern crate futures;
|
|||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
|
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
use actix_web::{client, server, middleware,
|
use actix_web::{
|
||||||
App, AsyncResponder, Body,
|
client, server, middleware,
|
||||||
HttpRequest, HttpResponse, HttpMessage, Error};
|
App, AsyncResponder, Body, HttpRequest, HttpResponse, HttpMessage, Error};
|
||||||
|
|
||||||
|
|
||||||
/// Stream client request response and then send body to a server response
|
/// Stream client request response and then send body to a server response
|
||||||
fn index(_req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
fn index(_req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||||
@ -44,7 +45,7 @@ fn main() {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("http-proxy");
|
let sys = actix::System::new("http-proxy");
|
||||||
|
|
||||||
let _addr = server::new(
|
server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
.resource("/streaming", |r| r.f(streaming))
|
.resource("/streaming", |r| r.f(streaming))
|
||||||
|
@ -89,7 +89,7 @@ fn main() {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("json-example");
|
let sys = actix::System::new("json-example");
|
||||||
|
|
||||||
let _ = server::new(|| {
|
server::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
|
@ -94,7 +94,7 @@ fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Start http server
|
// Start http server
|
||||||
let _ = server::new(move || {
|
server::new(move || {
|
||||||
App::with_state(AppState{executor: addr.clone()})
|
App::with_state(AppState{executor: addr.clone()})
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
|
@ -49,7 +49,7 @@ fn main() {
|
|||||||
let _ = env_logger::init();
|
let _ = env_logger::init();
|
||||||
let sys = actix::System::new("multipart-example");
|
let sys = actix::System::new("multipart-example");
|
||||||
|
|
||||||
let _ = server::new(
|
server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
.middleware(middleware::Logger::default()) // <- logger
|
.middleware(middleware::Logger::default()) // <- logger
|
||||||
.resource("/multipart", |r| r.method(http::Method::POST).a(index)))
|
.resource("/multipart", |r| r.method(http::Method::POST).a(index)))
|
||||||
|
@ -44,7 +44,7 @@ fn main() {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("protobuf-example");
|
let sys = actix::System::new("protobuf-example");
|
||||||
|
|
||||||
let _ = server::new(|| {
|
server::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
.resource("/", |r| r.method(http::Method::POST).f(index))})
|
.resource("/", |r| r.method(http::Method::POST).f(index))})
|
||||||
|
@ -53,7 +53,7 @@ fn main() {
|
|||||||
let addr = SyncArbiter::start(3, move || DbExecutor(pool.clone()));
|
let addr = SyncArbiter::start(3, move || DbExecutor(pool.clone()));
|
||||||
|
|
||||||
// Start http server
|
// Start http server
|
||||||
let _ = server::new(move || {
|
server::new(move || {
|
||||||
App::with_state(State{db: addr.clone()})
|
App::with_state(State{db: addr.clone()})
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
|
@ -55,10 +55,10 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for MyWebSocket {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
::std::env::set_var("RUST_LOG", "actix_web=info");
|
::std::env::set_var("RUST_LOG", "actix_web=info");
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("ws-example");
|
let sys = actix::System::new("ws-example");
|
||||||
|
|
||||||
let _ = server::new(
|
server::new(
|
||||||
|| App::with_state(AppState{counter: Cell::new(0)})
|
|| App::with_state(AppState{counter: Cell::new(0)})
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
|
@ -30,10 +30,10 @@ fn index(req: HttpRequest<State>) -> Result<HttpResponse, Error> {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
::std::env::set_var("RUST_LOG", "actix_web=info");
|
::std::env::set_var("RUST_LOG", "actix_web=info");
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("tera-example");
|
let sys = actix::System::new("tera-example");
|
||||||
|
|
||||||
let _ = server::new(|| {
|
server::new(|| {
|
||||||
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"));
|
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"));
|
||||||
|
|
||||||
App::with_state(State{template: tera})
|
App::with_state(State{template: tera})
|
||||||
|
@ -29,7 +29,7 @@ fn main() {
|
|||||||
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
|
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
|
||||||
builder.set_certificate_chain_file("cert.pem").unwrap();
|
builder.set_certificate_chain_file("cert.pem").unwrap();
|
||||||
|
|
||||||
let _ = server::new(
|
server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
|
@ -4,7 +4,7 @@ extern crate env_logger;
|
|||||||
extern crate tokio_uds;
|
extern crate tokio_uds;
|
||||||
|
|
||||||
use actix::*;
|
use actix::*;
|
||||||
use actix_web::*;
|
use actix_web::{middleware, server, App, HttpRequest};
|
||||||
use tokio_uds::UnixListener;
|
use tokio_uds::UnixListener;
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ fn main() {
|
|||||||
|
|
||||||
let listener = UnixListener::bind(
|
let listener = UnixListener::bind(
|
||||||
"/tmp/actix-uds.socket", Arbiter::handle()).expect("bind failed");
|
"/tmp/actix-uds.socket", Arbiter::handle()).expect("bind failed");
|
||||||
HttpServer::new(
|
server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
// enable logger
|
// enable logger
|
||||||
.middleware(middleware::Logger::default())
|
.middleware(middleware::Logger::default())
|
||||||
|
@ -17,7 +17,7 @@ extern crate actix_web;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use actix::*;
|
use actix::*;
|
||||||
use actix_web::{http, fs, ws, App, HttpRequest, HttpResponse, HttpServer, Error};
|
use actix_web::{http, fs, ws, server::HttpServer, App, HttpRequest, HttpResponse, Error};
|
||||||
|
|
||||||
mod codec;
|
mod codec;
|
||||||
mod server;
|
mod server;
|
||||||
@ -183,7 +183,7 @@ fn main() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Create Http server with websocket support
|
// Create Http server with websocket support
|
||||||
let addr = HttpServer::new(
|
HttpServer::new(
|
||||||
move || {
|
move || {
|
||||||
// Websocket sessions state
|
// Websocket sessions state
|
||||||
let state = WsChatSessionState { addr: server.clone() };
|
let state = WsChatSessionState { addr: server.clone() };
|
||||||
|
@ -45,7 +45,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for MyWebSocket {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
::std::env::set_var("RUST_LOG", "actix_web=info");
|
::std::env::set_var("RUST_LOG", "actix_web=info");
|
||||||
let _ = env_logger::init();
|
env_logger::init();
|
||||||
let sys = actix::System::new("ws-example");
|
let sys = actix::System::new("ws-example");
|
||||||
|
|
||||||
server::new(
|
server::new(
|
||||||
|
@ -179,7 +179,7 @@ session data.
|
|||||||
```rust
|
```rust
|
||||||
# extern crate actix;
|
# extern crate actix;
|
||||||
# extern crate actix_web;
|
# extern crate actix_web;
|
||||||
use actix_web::*;
|
use actix_web::{server, App, HttpRequest, Result};
|
||||||
use actix_web::middleware::{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> {
|
||||||
@ -196,7 +196,7 @@ fn index(mut req: HttpRequest) -> Result<&'static str> {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
# let sys = actix::System::new("basic-example");
|
# let sys = actix::System::new("basic-example");
|
||||||
HttpServer::new(
|
server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
.middleware(SessionStorage::new( // <- create session middleware
|
.middleware(SessionStorage::new( // <- create session middleware
|
||||||
CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend
|
CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend
|
||||||
|
@ -69,7 +69,7 @@ The full source of src/main.rs is listed below:
|
|||||||
```rust
|
```rust
|
||||||
# use std::thread;
|
# use std::thread;
|
||||||
extern crate actix_web;
|
extern crate actix_web;
|
||||||
use actix_web::{App, HttpRequest, HttpResponse, HttpServer};
|
use actix_web::{server, App, HttpRequest, HttpResponse};
|
||||||
|
|
||||||
fn index(req: HttpRequest) -> &'static str {
|
fn index(req: HttpRequest) -> &'static str {
|
||||||
"Hello world!"
|
"Hello world!"
|
||||||
@ -80,7 +80,7 @@ fn main() {
|
|||||||
# // If copying this example in show-all mode, make sure you skip the thread spawn
|
# // If copying this example in show-all mode, make sure you skip the thread spawn
|
||||||
# // call.
|
# // call.
|
||||||
# thread::spawn(|| {
|
# thread::spawn(|| {
|
||||||
HttpServer::new(
|
server::HttpServer::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
.resource("/", |r| r.f(index)))
|
.resource("/", |r| r.f(index)))
|
||||||
.bind("127.0.0.1:8088").expect("Can not bind to 127.0.0.1:8088")
|
.bind("127.0.0.1:8088").expect("Can not bind to 127.0.0.1:8088")
|
||||||
|
@ -45,10 +45,10 @@ Multiple applications can be served with one server:
|
|||||||
# extern crate tokio_core;
|
# extern crate tokio_core;
|
||||||
# use tokio_core::net::TcpStream;
|
# use tokio_core::net::TcpStream;
|
||||||
# use std::net::SocketAddr;
|
# use std::net::SocketAddr;
|
||||||
use actix_web::{App, HttpResponse, HttpServer};
|
use actix_web::{server, App, HttpResponse};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
HttpServer::new(|| vec![
|
server::new(|| vec![
|
||||||
App::new()
|
App::new()
|
||||||
.prefix("/app1")
|
.prefix("/app1")
|
||||||
.resource("/", |r| r.f(|r| HttpResponse::Ok())),
|
.resource("/", |r| r.f(|r| HttpResponse::Ok())),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Server
|
# Server
|
||||||
|
|
||||||
The [**HttpServer**](../actix_web/struct.HttpServer.html) type is responsible for
|
The [**HttpServer**](../actix_web/server/struct.HttpServer.html) type is responsible for
|
||||||
serving http requests.
|
serving http requests.
|
||||||
|
|
||||||
`HttpServer` accepts an application factory as a parameter, and the
|
`HttpServer` accepts an application factory as a parameter, and the
|
||||||
@ -18,13 +18,12 @@ To start the http server, one of the start methods.
|
|||||||
```rust
|
```rust
|
||||||
# extern crate actix;
|
# extern crate actix;
|
||||||
# extern crate actix_web;
|
# extern crate actix_web;
|
||||||
use actix::*;
|
use actix_web::{server::HttpServer, App, HttpResponse};
|
||||||
use actix_web::{server, App, HttpResponse};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let sys = actix::System::new("guide");
|
let sys = actix::System::new("guide");
|
||||||
|
|
||||||
server::new(
|
HttpServer::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
.resource("/", |r| r.f(|_| HttpResponse::Ok())))
|
.resource("/", |r| r.f(|_| HttpResponse::Ok())))
|
||||||
.bind("127.0.0.1:59080").unwrap()
|
.bind("127.0.0.1:59080").unwrap()
|
||||||
@ -54,8 +53,7 @@ address of the started http server. It accepts several messages:
|
|||||||
# use futures::Future;
|
# use futures::Future;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use actix::*;
|
use actix_web::{server, App, HttpResponse};
|
||||||
use actix_web::{server, App, HttpResponse, HttpServer};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
@ -87,7 +85,7 @@ can be overridden with the `HttpServer::threads()` method.
|
|||||||
```rust
|
```rust
|
||||||
# extern crate actix_web;
|
# extern crate actix_web;
|
||||||
# extern crate tokio_core;
|
# extern crate tokio_core;
|
||||||
use actix_web::{App, HttpServer, HttpResponse};
|
use actix_web::{App, HttpResponse, server::HttpServer};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
HttpServer::new(
|
HttpServer::new(
|
||||||
@ -123,7 +121,7 @@ fn main() {
|
|||||||
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
|
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
|
||||||
builder.set_certificate_chain_file("cert.pem").unwrap();
|
builder.set_certificate_chain_file("cert.pem").unwrap();
|
||||||
|
|
||||||
HttpServer::new(
|
server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
.resource("/index.html", |r| r.f(index)))
|
.resource("/index.html", |r| r.f(index)))
|
||||||
.bind("127.0.0.1:8080").unwrap()
|
.bind("127.0.0.1:8080").unwrap()
|
||||||
|
@ -130,7 +130,7 @@ Let's create a response for a custom type that serializes to an `application/jso
|
|||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use] extern crate serde_derive;
|
||||||
use actix_web::{App, HttpServer, HttpRequest, HttpResponse, Error, Responder, http};
|
use actix_web::{server, App, HttpRequest, HttpResponse, Error, Responder, http};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct MyObj {
|
struct MyObj {
|
||||||
@ -160,7 +160,7 @@ fn index(req: HttpRequest) -> MyObj {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let sys = actix::System::new("example");
|
let sys = actix::System::new("example");
|
||||||
|
|
||||||
HttpServer::new(
|
server::new(
|
||||||
|| App::new()
|
|| App::new()
|
||||||
.resource("/", |r| r.method(http::Method::GET).f(index)))
|
.resource("/", |r| r.method(http::Method::GET).f(index)))
|
||||||
.bind("127.0.0.1:8088").unwrap()
|
.bind("127.0.0.1:8088").unwrap()
|
||||||
|
@ -162,7 +162,7 @@ impl ArbiterService for ClientConnector {}
|
|||||||
|
|
||||||
impl Default for ClientConnector {
|
impl Default for ClientConnector {
|
||||||
fn default() -> ClientConnector {
|
fn default() -> ClientConnector {
|
||||||
let modified = Rc::new(Cell::new(false));
|
let _modified = Rc::new(Cell::new(false));
|
||||||
|
|
||||||
#[cfg(all(feature="alpn"))]
|
#[cfg(all(feature="alpn"))]
|
||||||
{
|
{
|
||||||
@ -173,8 +173,8 @@ impl Default for ClientConnector {
|
|||||||
{
|
{
|
||||||
let builder = TlsConnector::builder().unwrap();
|
let builder = TlsConnector::builder().unwrap();
|
||||||
ClientConnector {
|
ClientConnector {
|
||||||
pool: Rc::new(Pool::new(Rc::clone(&modified))),
|
pool: Rc::new(Pool::new(Rc::clone(&_modified))),
|
||||||
pool_modified: modified,
|
pool_modified: _modified,
|
||||||
connector: builder.build().unwrap(),
|
connector: builder.build().unwrap(),
|
||||||
conn_lifetime: Duration::from_secs(15),
|
conn_lifetime: Duration::from_secs(15),
|
||||||
conn_keep_alive: Duration::from_secs(75),
|
conn_keep_alive: Duration::from_secs(75),
|
||||||
@ -190,8 +190,8 @@ impl Default for ClientConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(feature="alpn", feature="tls")))]
|
#[cfg(not(any(feature="alpn", feature="tls")))]
|
||||||
ClientConnector {pool: Rc::new(Pool::new(Rc::clone(&modified))),
|
ClientConnector {pool: Rc::new(Pool::new(Rc::clone(&_modified))),
|
||||||
pool_modified: modified,
|
pool_modified: _modified,
|
||||||
conn_lifetime: Duration::from_secs(15),
|
conn_lifetime: Duration::from_secs(15),
|
||||||
conn_keep_alive: Duration::from_secs(75),
|
conn_keep_alive: Duration::from_secs(75),
|
||||||
limit: 100,
|
limit: 100,
|
||||||
@ -459,7 +459,7 @@ impl ClientConnector {
|
|||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut next = None;
|
let mut next = None;
|
||||||
|
|
||||||
for (_, waiters) in &mut self.waiters {
|
for waiters in self.waiters.values_mut() {
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
while idx < waiters.len() {
|
while idx < waiters.len() {
|
||||||
if waiters[idx].wait <= now {
|
if waiters[idx].wait <= now {
|
||||||
|
@ -145,7 +145,6 @@ pub use httprequest::HttpRequest;
|
|||||||
pub use httpresponse::HttpResponse;
|
pub use httpresponse::HttpResponse;
|
||||||
pub use handler::{Either, Responder, AsyncResponder, FromRequest, FutureResponse, State};
|
pub use handler::{Either, Responder, AsyncResponder, FromRequest, FutureResponse, State};
|
||||||
pub use context::HttpContext;
|
pub use context::HttpContext;
|
||||||
pub use server::HttpServer;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod httpcodes;
|
pub mod httpcodes;
|
||||||
|
@ -32,7 +32,9 @@ use httpresponse::HttpResponse;
|
|||||||
/// max buffer size 64k
|
/// max buffer size 64k
|
||||||
pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
|
pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
|
||||||
|
|
||||||
/// Create new http server with application factory
|
/// Create new http server with application factory.
|
||||||
|
///
|
||||||
|
/// This is shortcut for `server::HttpServer::new()` method.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate actix;
|
/// # extern crate actix;
|
||||||
@ -46,7 +48,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
|
|||||||
/// server::new(
|
/// server::new(
|
||||||
/// || App::new()
|
/// || App::new()
|
||||||
/// .resource("/", |r| r.f(|_| HttpResponse::Ok())))
|
/// .resource("/", |r| r.f(|_| HttpResponse::Ok())))
|
||||||
/// .bind("127.0.0.1:59080").unwrap()
|
/// .bind("127.0.0.1:59090").unwrap()
|
||||||
/// .start();
|
/// .start();
|
||||||
///
|
///
|
||||||
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));
|
||||||
|
Loading…
Reference in New Issue
Block a user