diff --git a/Cargo.toml b/Cargo.toml index 238a2d1ad..23ab441ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ features = [] [dev-dependencies] env_logger = "*" +reqwest = "0.8" [profile.release] lto = true diff --git a/src/application.rs b/src/application.rs index b18383e6f..da6cee971 100644 --- a/src/application.rs +++ b/src/application.rs @@ -12,6 +12,7 @@ use httpresponse::HttpResponse; use server::HttpHandler; +/// Middleware definition #[allow(unused_variables)] pub trait Middleware { @@ -21,7 +22,7 @@ pub trait Middleware { } /// Method is called when handler returns response, - /// but before sending body stream to peer. + /// but before sending body streams to peer. fn response(&self, req: &mut HttpRequest, resp: HttpResponse) -> HttpResponse { resp } diff --git a/src/lib.rs b/src/lib.rs index b75c200b1..cef2adea6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -//! Http framework for [Actix](https://github.com/fafhrd91/actix) +//! Web framework for [Actix](https://github.com/fafhrd91/actix) #[macro_use] extern crate log; diff --git a/tests/test_server.rs b/tests/test_server.rs index 29a3f992d..3f78e4aec 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -1,15 +1,13 @@ extern crate actix; extern crate actix_web; -extern crate futures; extern crate tokio_core; +extern crate reqwest; -use std::net; +use std::{net, thread}; use std::str::FromStr; -use std::io::prelude::*; use actix::*; use actix_web::*; -use futures::Future; -use tokio_core::net::{TcpStream, TcpListener}; +use tokio_core::net::TcpListener; fn create_server() -> HttpServer> { @@ -24,41 +22,28 @@ fn create_server() -> HttpServer> { #[test] fn test_serve() { - let sys = System::new("test"); + thread::spawn(|| { + let sys = System::new("test"); - let srv = create_server(); - srv.serve::<_, ()>("127.0.0.1:58902").unwrap(); - let addr = net::SocketAddr::from_str("127.0.0.1:58902").unwrap(); - - Arbiter::handle().spawn( - TcpStream::connect(&addr, Arbiter::handle()).and_then(|mut stream| { - let _ = stream.write("GET /\r\n\r\n ".as_ref()); - Arbiter::system().send(msgs::SystemExit(0)); - futures::future::ok(()) - }).map_err(|_| panic!("should not happen")) - ); - - sys.run(); + let srv = create_server(); + srv.serve::<_, ()>("127.0.0.1:58902").unwrap(); + sys.run(); + }); + assert!(reqwest::get("http://localhost:58906/").unwrap().status().is_success()); } #[test] fn test_serve_incoming() { - let sys = System::new("test"); + thread::spawn(|| { + let sys = System::new("test"); - let srv = create_server(); - let addr = net::SocketAddr::from_str("127.0.0.1:58906").unwrap(); - let tcp = TcpListener::bind(&addr, Arbiter::handle()).unwrap(); - srv.serve_incoming::<_, ()>(tcp.incoming()).unwrap(); - let addr = net::SocketAddr::from_str("127.0.0.1:58906").unwrap(); + let srv = create_server(); + let addr = net::SocketAddr::from_str("127.0.0.1:58906").unwrap(); + let tcp = TcpListener::bind(&addr, Arbiter::handle()).unwrap(); + srv.serve_incoming::<_, ()>(tcp.incoming()).unwrap(); + sys.run(); - // connect - Arbiter::handle().spawn( - TcpStream::connect(&addr, Arbiter::handle()).and_then(|mut stream| { - let _ = stream.write("GET /\r\n\r\n ".as_ref()); - Arbiter::system().send(msgs::SystemExit(0)); - futures::future::ok(()) - }).map_err(|_| panic!("should not happen")) - ); + }); - sys.run(); + assert!(reqwest::get("http://localhost:58906/").unwrap().status().is_success()); }