gdritter repos httputils / 81a9f6b
Early state, nothing really done Getty Ritter 8 years ago
2 changed file(s) with 62 addition(s) and 0 deletion(s). Collapse all Expand all
1 [package]
2 name = "httputils"
3 version = "0.1.0"
4 authors = ["Getty Ritter <gdritter@galois.com>"]
5
6 [dependencies]
7 hyper = "*"
1 extern crate hyper;
2
3 // use std::io::Write;
4
5 use hyper::Server;
6 use hyper::server::{Request,Response};
7 use hyper::net::Fresh;
8
9 #[derive(Debug, Clone)]
10 struct Delegate {
11 name: String,
12 }
13
14 #[derive(Debug, Clone)]
15 struct PathSpec {
16 forPath: Option<String>,
17 forDomain: Option<String>,
18 delegateTo: Delegate,
19 }
20
21 fn find_delegate(req: Request, delegates: Vec<PathSpec>) -> Option<Delegate> {
22 for d in delegates.iter() {
23 if let Some(ref domain) = d.forDomain {
24 }
25 if let Some(ref path) = d.forPath {
26
27 }
28 return Some(d.delegateTo.clone());
29 }
30 return None;
31 }
32
33 fn dispatch(req: Request, res: Response<Fresh>, delegates: Vec<PathSpec>) {
34 println!("{:?}", req.headers);
35 res.send(b"Unhandled request.").unwrap();
36 }
37
38 fn hello(req: Request, res: Response<Fresh>) {
39 res.send(b"Unhandled request.").unwrap();
40 }
41
42 fn main() {
43 let sample: Vec<PathSpec> = vec![
44 PathSpec { forPath: None,
45 forDomain: None,
46 delegateTo: Delegate { name: "default".to_owned() } } ];
47 match Server::http("127.0.0.1:8080") {
48 Ok(s) => {
49 let _ = s.handle(hello);
50 }
51 Err(e) => {
52 println!("Unable to run server: {:?}", e);
53 }
54 }
55 }