1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 16:02:59 +01:00
actix-extras/tests/test_h1v2.rs

57 lines
1.7 KiB
Rust
Raw Normal View History

2018-10-05 01:22:00 +02:00
extern crate actix;
2018-10-05 02:00:27 +02:00
extern crate actix_http;
2018-10-05 01:22:00 +02:00
extern crate actix_net;
extern crate actix_web;
extern crate futures;
use std::thread;
use actix::System;
use actix_net::server::Server;
use actix_net::service::{IntoNewService, IntoService};
2018-10-05 02:00:27 +02:00
use actix_web::{client, test};
2018-10-05 01:22:00 +02:00
use futures::future;
2018-10-05 02:00:27 +02:00
use actix_http::server::h1disp::Http1Dispatcher;
use actix_http::server::{KeepAlive, ServiceConfig};
use actix_http::{Error, HttpResponse};
2018-10-05 01:22:00 +02:00
#[test]
fn test_h1_v2() {
let addr = test::TestServer::unused_addr();
thread::spawn(move || {
Server::new()
.bind("test", addr, move || {
2018-10-05 02:00:27 +02:00
let settings = ServiceConfig::build()
2018-10-05 01:22:00 +02:00
.keep_alive(KeepAlive::Disabled)
.client_timeout(1000)
.client_shutdown(1000)
.server_hostname("localhost")
.server_address(addr)
.finish();
(move |io| {
let pool = settings.request_pool();
Http1Dispatcher::new(
io,
pool,
(|req| {
println!("REQ: {:?}", req);
future::ok::<_, Error>(HttpResponse::Ok().finish())
}).into_service(),
)
}).into_new_service()
}).unwrap()
.run();
});
let mut sys = System::new("test");
{
let req = client::ClientRequest::get(format!("http://{}/", addr).as_str())
.finish()
.unwrap();
let response = sys.block_on(req.send()).unwrap();
assert!(response.status().is_success());
}
}