1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

do not re-export HttpServer from server module

This commit is contained in:
Nikolay Kim 2018-04-06 08:40:11 -07:00
parent 12586db15c
commit 2dafd9c681
21 changed files with 47 additions and 47 deletions

View File

@ -8,8 +8,8 @@ extern crate futures;
use futures::Stream;
use std::{io, env};
use actix_web::{error, fs, pred,
App, HttpRequest, HttpResponse, HttpServer, Result, Error};
use actix_web::{error, fs, pred, server,
App, HttpRequest, HttpResponse, Result, Error};
use actix_web::http::{Method, StatusCode};
use actix_web::middleware::{self, RequestSession};
use futures::future::{FutureResult, result};
@ -99,7 +99,7 @@ fn main() {
env_logger::init();
let sys = actix::System::new("basic-example");
let addr = HttpServer::new(
let addr = server::new(
|| App::new()
// enable logger
.middleware(middleware::Logger::default())

View File

@ -4,9 +4,10 @@ extern crate futures;
extern crate env_logger;
use futures::{Future, Stream};
use actix_web::{client, server, middleware,
App, AsyncResponder, Body,
HttpRequest, HttpResponse, HttpMessage, Error};
use actix_web::{
client, server, middleware,
App, AsyncResponder, Body, HttpRequest, HttpResponse, HttpMessage, Error};
/// Stream client request response and then send body to a server response
fn index(_req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
@ -44,7 +45,7 @@ fn main() {
env_logger::init();
let sys = actix::System::new("http-proxy");
let _addr = server::new(
server::new(
|| App::new()
.middleware(middleware::Logger::default())
.resource("/streaming", |r| r.f(streaming))

View File

@ -89,7 +89,7 @@ fn main() {
env_logger::init();
let sys = actix::System::new("json-example");
let _ = server::new(|| {
server::new(|| {
App::new()
// enable logger
.middleware(middleware::Logger::default())

View File

@ -94,7 +94,7 @@ fn main() {
});
// Start http server
let _ = server::new(move || {
server::new(move || {
App::with_state(AppState{executor: addr.clone()})
// enable logger
.middleware(middleware::Logger::default())

View File

@ -49,7 +49,7 @@ fn main() {
let _ = env_logger::init();
let sys = actix::System::new("multipart-example");
let _ = server::new(
server::new(
|| App::new()
.middleware(middleware::Logger::default()) // <- logger
.resource("/multipart", |r| r.method(http::Method::POST).a(index)))

View File

@ -44,7 +44,7 @@ fn main() {
env_logger::init();
let sys = actix::System::new("protobuf-example");
let _ = server::new(|| {
server::new(|| {
App::new()
.middleware(middleware::Logger::default())
.resource("/", |r| r.method(http::Method::POST).f(index))})

View File

@ -53,7 +53,7 @@ fn main() {
let addr = SyncArbiter::start(3, move || DbExecutor(pool.clone()));
// Start http server
let _ = server::new(move || {
server::new(move || {
App::with_state(State{db: addr.clone()})
// enable logger
.middleware(middleware::Logger::default())

View File

@ -55,10 +55,10 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for MyWebSocket {
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
let _ = env_logger::init();
env_logger::init();
let sys = actix::System::new("ws-example");
let _ = server::new(
server::new(
|| App::with_state(AppState{counter: Cell::new(0)})
// enable logger
.middleware(middleware::Logger::default())

View File

@ -30,10 +30,10 @@ fn index(req: HttpRequest<State>) -> Result<HttpResponse, Error> {
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
let _ = env_logger::init();
env_logger::init();
let sys = actix::System::new("tera-example");
let _ = server::new(|| {
server::new(|| {
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"));
App::with_state(State{template: tera})

View File

@ -29,7 +29,7 @@ fn main() {
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
builder.set_certificate_chain_file("cert.pem").unwrap();
let _ = server::new(
server::new(
|| App::new()
// enable logger
.middleware(middleware::Logger::default())

View File

@ -4,7 +4,7 @@ extern crate env_logger;
extern crate tokio_uds;
use actix::*;
use actix_web::*;
use actix_web::{middleware, server, App, HttpRequest};
use tokio_uds::UnixListener;
@ -19,7 +19,7 @@ fn main() {
let listener = UnixListener::bind(
"/tmp/actix-uds.socket", Arbiter::handle()).expect("bind failed");
HttpServer::new(
server::new(
|| App::new()
// enable logger
.middleware(middleware::Logger::default())

View File

@ -17,7 +17,7 @@ extern crate actix_web;
use std::time::Instant;
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 server;
@ -183,7 +183,7 @@ fn main() {
}));
// Create Http server with websocket support
let addr = HttpServer::new(
HttpServer::new(
move || {
// Websocket sessions state
let state = WsChatSessionState { addr: server.clone() };

View File

@ -45,7 +45,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for MyWebSocket {
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
let _ = env_logger::init();
env_logger::init();
let sys = actix::System::new("ws-example");
server::new(

View File

@ -179,7 +179,7 @@ session data.
```rust
# extern crate actix;
# extern crate actix_web;
use actix_web::*;
use actix_web::{server, App, HttpRequest, Result};
use actix_web::middleware::{RequestSession, SessionStorage, CookieSessionBackend};
fn index(mut req: HttpRequest) -> Result<&'static str> {
@ -196,7 +196,7 @@ fn index(mut req: HttpRequest) -> Result<&'static str> {
fn main() {
# let sys = actix::System::new("basic-example");
HttpServer::new(
server::new(
|| App::new()
.middleware(SessionStorage::new( // <- create session middleware
CookieSessionBackend::build(&[0; 32]) // <- create cookie session backend

View File

@ -69,7 +69,7 @@ The full source of src/main.rs is listed below:
```rust
# use std::thread;
extern crate actix_web;
use actix_web::{App, HttpRequest, HttpResponse, HttpServer};
use actix_web::{server, App, HttpRequest, HttpResponse};
fn index(req: HttpRequest) -> &'static str {
"Hello world!"
@ -80,7 +80,7 @@ fn main() {
# // If copying this example in show-all mode, make sure you skip the thread spawn
# // call.
# thread::spawn(|| {
HttpServer::new(
server::HttpServer::new(
|| App::new()
.resource("/", |r| r.f(index)))
.bind("127.0.0.1:8088").expect("Can not bind to 127.0.0.1:8088")

View File

@ -45,10 +45,10 @@ Multiple applications can be served with one server:
# extern crate tokio_core;
# use tokio_core::net::TcpStream;
# use std::net::SocketAddr;
use actix_web::{App, HttpResponse, HttpServer};
use actix_web::{server, App, HttpResponse};
fn main() {
HttpServer::new(|| vec![
server::new(|| vec![
App::new()
.prefix("/app1")
.resource("/", |r| r.f(|r| HttpResponse::Ok())),

View File

@ -1,6 +1,6 @@
# 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.
`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
# extern crate actix;
# extern crate actix_web;
use actix::*;
use actix_web::{server, App, HttpResponse};
use actix_web::{server::HttpServer, App, HttpResponse};
fn main() {
let sys = actix::System::new("guide");
server::new(
HttpServer::new(
|| App::new()
.resource("/", |r| r.f(|_| HttpResponse::Ok())))
.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 std::thread;
use std::sync::mpsc;
use actix::*;
use actix_web::{server, App, HttpResponse, HttpServer};
use actix_web::{server, App, HttpResponse};
fn main() {
let (tx, rx) = mpsc::channel();
@ -87,7 +85,7 @@ can be overridden with the `HttpServer::threads()` method.
```rust
# extern crate actix_web;
# extern crate tokio_core;
use actix_web::{App, HttpServer, HttpResponse};
use actix_web::{App, HttpResponse, server::HttpServer};
fn main() {
HttpServer::new(
@ -123,7 +121,7 @@ fn main() {
builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
builder.set_certificate_chain_file("cert.pem").unwrap();
HttpServer::new(
server::new(
|| App::new()
.resource("/index.html", |r| r.f(index)))
.bind("127.0.0.1:8080").unwrap()

View File

@ -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_json;
#[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)]
struct MyObj {
@ -160,7 +160,7 @@ fn index(req: HttpRequest) -> MyObj {
fn main() {
let sys = actix::System::new("example");
HttpServer::new(
server::new(
|| App::new()
.resource("/", |r| r.method(http::Method::GET).f(index)))
.bind("127.0.0.1:8088").unwrap()

View File

@ -162,7 +162,7 @@ impl ArbiterService for ClientConnector {}
impl Default for ClientConnector {
fn default() -> ClientConnector {
let modified = Rc::new(Cell::new(false));
let _modified = Rc::new(Cell::new(false));
#[cfg(all(feature="alpn"))]
{
@ -173,8 +173,8 @@ impl Default for ClientConnector {
{
let builder = TlsConnector::builder().unwrap();
ClientConnector {
pool: Rc::new(Pool::new(Rc::clone(&modified))),
pool_modified: modified,
pool: Rc::new(Pool::new(Rc::clone(&_modified))),
pool_modified: _modified,
connector: builder.build().unwrap(),
conn_lifetime: Duration::from_secs(15),
conn_keep_alive: Duration::from_secs(75),
@ -190,8 +190,8 @@ impl Default for ClientConnector {
}
#[cfg(not(any(feature="alpn", feature="tls")))]
ClientConnector {pool: Rc::new(Pool::new(Rc::clone(&modified))),
pool_modified: modified,
ClientConnector {pool: Rc::new(Pool::new(Rc::clone(&_modified))),
pool_modified: _modified,
conn_lifetime: Duration::from_secs(15),
conn_keep_alive: Duration::from_secs(75),
limit: 100,
@ -459,7 +459,7 @@ impl ClientConnector {
let now = Instant::now();
let mut next = None;
for (_, waiters) in &mut self.waiters {
for waiters in self.waiters.values_mut() {
let mut idx = 0;
while idx < waiters.len() {
if waiters[idx].wait <= now {

View File

@ -145,7 +145,6 @@ pub use httprequest::HttpRequest;
pub use httpresponse::HttpResponse;
pub use handler::{Either, Responder, AsyncResponder, FromRequest, FutureResponse, State};
pub use context::HttpContext;
pub use server::HttpServer;
#[doc(hidden)]
pub mod httpcodes;

View File

@ -32,7 +32,9 @@ use httpresponse::HttpResponse;
/// max buffer size 64k
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
/// # extern crate actix;
@ -46,7 +48,7 @@ pub(crate) const MAX_WRITE_BUFFER_SIZE: usize = 65_536;
/// server::new(
/// || App::new()
/// .resource("/", |r| r.f(|_| HttpResponse::Ok())))
/// .bind("127.0.0.1:59080").unwrap()
/// .bind("127.0.0.1:59090").unwrap()
/// .start();
///
/// # actix::Arbiter::system().do_send(actix::msgs::SystemExit(0));