summaryrefslogtreecommitdiff
path: root/spider/src/response.rs
diff options
context:
space:
mode:
Diffstat (limited to 'spider/src/response.rs')
-rw-r--r--spider/src/response.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/spider/src/response.rs b/spider/src/response.rs
new file mode 100644
index 0000000..e192b22
--- /dev/null
+++ b/spider/src/response.rs
@@ -0,0 +1,35 @@
+use std::collections::HashMap;
+use std::fmt;
+
+pub struct Response {
+ status: i32,
+ headers: HashMap<String, String>,
+ body: String
+}
+
+impl Response {
+ pub fn new(body: &str) -> Response {
+ let headers: HashMap<String, String> = HashMap::new();
+ return Response {
+ status: 200,
+ headers: headers,
+ body: String::from(body)
+ };
+ }
+
+ pub fn format<'a>(&self) -> &'a [u8] {
+ 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;
+ }
+}
+
+impl fmt::Display for Response {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ return write!(f, "Response({})", self.status);
+ }
+}