diff options
Diffstat (limited to 'spider/src')
| -rw-r--r-- | spider/src/http_method.rs | 1 | ||||
| -rw-r--r-- | spider/src/http_server.rs | 5 | ||||
| -rw-r--r-- | spider/src/request.rs | 3 | ||||
| -rw-r--r-- | spider/src/response.rs | 9 |
4 files changed, 12 insertions, 6 deletions
diff --git a/spider/src/http_method.rs b/spider/src/http_method.rs index b1cc884..e308983 100644 --- a/spider/src/http_method.rs +++ b/spider/src/http_method.rs @@ -1,5 +1,6 @@ use std::fmt; +// TODO(andrew): add rest of the methods. pub enum HttpMethod { GET, POST } diff --git a/spider/src/http_server.rs b/spider/src/http_server.rs index 419f39e..a3f4bc2 100644 --- a/spider/src/http_server.rs +++ b/spider/src/http_server.rs @@ -7,6 +7,7 @@ use crate::response::Response; use crate::http_method::HttpMethod; pub trait HttpHandler { + // TODO(andrew): add default behaviour to handlers? fn do_get(&self, request: Request) -> Response; fn do_post(&self, request: Request) -> Response; } @@ -55,6 +56,9 @@ impl<T> HttpServer<T> where T: HttpHandler { let mut buf: [u8; 1024] = [0; 1024]; stream.peek(&mut buf).expect("Couldn't read from socket"); + // TODO(andrew): parse only headers as string and leave decoding of + // body to handler. + // TODO(andrew): read all body, not first 1024 bytes. // TODO(andrew): remove panic. let s = match str::from_utf8(&buf) { Ok(v) => v, @@ -68,6 +72,7 @@ impl<T> HttpServer<T> where T: HttpHandler { None => panic!("Request parsed with errors") }; + // TODO(andrew): add more methods. let response = match request.method { HttpMethod::GET => self.handler.do_get(request), HttpMethod::POST => self.handler.do_post(request) diff --git a/spider/src/request.rs b/spider/src/request.rs index 4fae0c5..c7d5ab0 100644 --- a/spider/src/request.rs +++ b/spider/src/request.rs @@ -24,7 +24,8 @@ impl Request { }; } - // TODO(andrew): Add some error handling. + // TODO(andrew): accept &[u8] instead of &str and add parsing of body. + // TODO(andrew): add some error handling. pub fn from(data: &str) -> Option<Request> { let lines = data.split("\r\n").collect::<Vec<&str>>(); diff --git a/spider/src/response.rs b/spider/src/response.rs index e192b22..35b2f00 100644 --- a/spider/src/response.rs +++ b/spider/src/response.rs @@ -1,6 +1,8 @@ use std::collections::HashMap; use std::fmt; +// TODO(andrew): add more flexible status structure. +// (Possibly with enum variants?) pub struct Response { status: i32, headers: HashMap<String, String>, @@ -18,13 +20,10 @@ impl Response { } pub fn format<'a>(&self) -> &'a [u8] { + // TODO(andrew): replace placeholder response with actual + // formatted response; let s = "HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nContent-Type: text/html\r\n\r\n<i>Hello</i>"; return s.as_bytes(); - - // let buf: &[u8]; - // buf = &[0; 1024]; -// - // return buf; } } |