From 04a3c64713ae4f0a7f1b5cfdab132f78cc33a862 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 14 Feb 2021 18:33:29 +0400 Subject: Renamed path field in Request struct to resource and implemented Display trait for HttpServer --- spider/src/request.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'spider/src/request.rs') diff --git a/spider/src/request.rs b/spider/src/request.rs index fa32bbd..db1f2ad 100644 --- a/spider/src/request.rs +++ b/spider/src/request.rs @@ -5,7 +5,7 @@ use crate::http_method::HttpMethod; pub struct Request { pub method: HttpMethod, - path: String, + resource: String, http_version: String, headers: HashMap, body: Vec, @@ -13,13 +13,13 @@ pub struct Request { impl Request { pub fn new( method: HttpMethod - , path: String + , resource: String , http_version: String , headers: HashMap , body: Vec ) -> Request { return Request { method, - path, + resource, http_version, headers, body, @@ -60,18 +60,19 @@ impl Request { headers.insert(String::from(line[0]), line[1..].join(" ")); } - let first_line = lines[0] + let request_line = lines[0] .trim_end_matches("\r\n") .split(" ") .collect::>(); - let method = String::from(first_line[0]); + let method = String::from(request_line[0]); match HttpMethod::parse(method) { Some(method) => return Some(Request::new( method, - String::from(first_line[1]), - String::from(first_line[2]), + // TODO(andrew): add parsing of resource line. + String::from(request_line[1]), + String::from(request_line[2]), headers, body )), None => return None @@ -81,7 +82,6 @@ impl Request { impl fmt::Display for Request { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - return write!(f, "Request({}, {})", self.method, self.path); + return write!(f, "Request({}, {})", self.method, self.resource); } } - -- cgit v1.2.3