Files
hyper/examples/hello.rs
Sean McArthur 6ade21aa7f feat(server): change default dispatcher
- Deprecates the `no_proto` configuration on `Server`. It is always
  enabled.
- Deprecates all pieces related to tokio-proto.
- Makes the tokio-proto crate optional, and the `server-proto` feature
  can be used to completely remove the dependency. It is enabled by
  default.
2017-12-28 19:15:57 -08:00

26 lines
783 B
Rust

#![deny(warnings)]
extern crate hyper;
extern crate futures;
extern crate pretty_env_logger;
use hyper::header::{ContentLength, ContentType};
use hyper::server::{Http, Response, const_service, service_fn};
static PHRASE: &'static [u8] = b"Hello World!";
fn main() {
pretty_env_logger::init().unwrap();
let addr = ([127, 0, 0, 1], 3000).into();
let new_service = const_service(service_fn(|_| {
Ok(Response::<hyper::Body>::new()
.with_header(ContentLength(PHRASE.len() as u64))
.with_header(ContentType::plaintext())
.with_body(PHRASE))
}));
let server = Http::new().bind(&addr, new_service).unwrap();
println!("Listening on http://{} with 1 thread.", server.local_addr().unwrap());
server.run().unwrap();
}