main.rs 686 B

123456789101112131415161718192021222324
  1. extern crate hyper;
  2. use hyper::server::{Server, Request, Response};
  3. use hyper::uri::RequestUri;
  4. use hyper::header::ContentType;
  5. use hyper::header;
  6. const HELLO_WORLD: &'static [u8; 13] = b"Hello, World!";
  7. fn main() {
  8. Server::http("0.0.0.0:8080").unwrap().handle(handler).unwrap();
  9. }
  10. fn handler(req: Request, mut res: Response) {
  11. match (req.method, req.uri) {
  12. (hyper::Get, RequestUri::AbsolutePath(ref path)) if path == "/plaintext" => {
  13. res.headers_mut().set(ContentType("text/plain".parse().unwrap()));
  14. res.headers_mut().set(header::Server("Hyper".to_owned()));
  15. res.send(HELLO_WORLD).unwrap();
  16. }
  17. _ => (),
  18. }
  19. }