summaryrefslogtreecommitdiff
path: root/spider/src/response.rs
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-02-14 13:43:29 +0400
committerAndrew <saintruler@gmail.com>2021-02-14 13:43:29 +0400
commit679f1c88ea9c56110f8f66f6f253fce30704e45e (patch)
treec8eba9915a827c9dd667a1e8c553dda4f98365cc /spider/src/response.rs
parent626e11a725934b64260e17e68d273727be76c57e (diff)
Changed structure of library
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);
+ }
+}