1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-21 09:23:54 +00:00
actix-web/examples/framed_hello.rs

36 lines
1,005 B
Rust
Raw Normal View History

2018-11-24 13:38:17 +00:00
extern crate env_logger;
2018-11-28 06:12:04 +00:00
extern crate log;
2018-11-24 13:38:17 +00:00
extern crate actix_http;
extern crate actix_net;
2018-11-28 06:12:04 +00:00
extern crate bytes;
2018-11-24 13:38:17 +00:00
extern crate futures;
extern crate http;
2018-11-28 06:12:04 +00:00
use actix_http::{h1, Response, SendResponse, ServiceConfig};
2018-11-24 13:38:17 +00:00
use actix_net::codec::Framed;
2018-11-28 06:12:04 +00:00
use actix_net::framed::IntoFramed;
2018-11-24 13:38:17 +00:00
use actix_net::server::Server;
use actix_net::service::NewServiceExt;
2018-11-28 06:12:04 +00:00
use actix_net::stream::TakeItem;
2018-11-24 13:38:17 +00:00
use futures::Future;
use std::env;
fn main() {
env::set_var("RUST_LOG", "framed_hello=info");
env_logger::init();
2018-11-28 06:12:04 +00:00
Server::new()
.bind("framed_hello", "127.0.0.1:8080", || {
IntoFramed::new(|| h1::Codec::new(ServiceConfig::default()))
.and_then(TakeItem::new().map_err(|_| ()))
.and_then(|(_req, _framed): (_, Framed<_, _>)| {
SendResponse::send(_framed, Response::Ok().body("Hello world!"))
.map_err(|_| ())
.map(|_| ())
})
2018-12-06 22:32:52 +00:00
})
.unwrap()
2018-11-28 06:12:04 +00:00
.run();
2018-11-24 13:38:17 +00:00
}