1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-01-18 22:01:50 +01:00
actix-web/examples/framed_hello.rs

27 lines
838 B
Rust
Raw Normal View History

2018-12-10 18:08:33 -08:00
use actix_codec::Framed;
2018-11-28 09:42:04 +03:30
use actix_http::{h1, Response, SendResponse, ServiceConfig};
2018-12-10 18:08:33 -08:00
use actix_server::Server;
use actix_service::NewService;
use actix_utils::framed::IntoFramed;
use actix_utils::stream::TakeItem;
2018-11-24 17:08:17 +03:30
use futures::Future;
use std::env;
fn main() {
env::set_var("RUST_LOG", "framed_hello=info");
env_logger::init();
2018-12-10 18:08:33 -08:00
Server::build()
2018-11-28 09:42:04 +03:30
.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 14:32:52 -08:00
})
.unwrap()
2018-11-28 09:42:04 +03:30
.run();
2018-11-24 17:08:17 +03:30
}