summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-02-14 14:38:03 +0400
committerAndrew <saintruler@gmail.com>2021-02-14 14:38:03 +0400
commitad92fb3dc6a3350b7b8952be40c5c3a7aa543892 (patch)
tree24a11fc60e0922aa93ac2dfdece99b2e8dc36a10
parent053534d753439fcf47168f3515a03478d384be87 (diff)
Added more TODOs
-rw-r--r--blog/src/main.rs2
-rw-r--r--spider/src/http_method.rs1
-rw-r--r--spider/src/http_server.rs5
-rw-r--r--spider/src/request.rs3
-rw-r--r--spider/src/response.rs9
5 files changed, 13 insertions, 7 deletions
diff --git a/blog/src/main.rs b/blog/src/main.rs
index c779191..9693f88 100644
--- a/blog/src/main.rs
+++ b/blog/src/main.rs
@@ -20,7 +20,7 @@ impl MyHandler {
}
}
-
+// TODO(andrew): create logging package.
fn main() {
let handler = MyHandler::new();
let server = HttpServer::new("localhost", 3000, handler);
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;
}
}