From d5b264034299bcaa75f3bd21b4d36dba574c2295 Mon Sep 17 00:00:00 2001 From: Ali Shirvani Date: Sat, 24 Nov 2018 17:08:17 +0330 Subject: [PATCH] add framed_hello.rs --- examples/framed_hello.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/framed_hello.rs diff --git a/examples/framed_hello.rs b/examples/framed_hello.rs new file mode 100644 index 000000000..76d23d08c --- /dev/null +++ b/examples/framed_hello.rs @@ -0,0 +1,33 @@ +extern crate log; +extern crate env_logger; + +extern crate actix_http; +extern crate actix_net; +extern crate futures; +extern crate http; +extern crate bytes; + +use actix_http::{h1, ServiceConfig, SendResponse, Response}; +use actix_net::framed::IntoFramed; +use actix_net::codec::Framed; +use actix_net::stream::TakeItem; +use actix_net::server::Server; +use actix_net::service::NewServiceExt; +use futures::Future; +use std::env; + +fn main() { + env::set_var("RUST_LOG", "framed_hello=info"); + env_logger::init(); + + 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(|_| ()) + }) + }).unwrap().run(); +} +