From f2cdc940374a2eef7cdae9a34c90a52e527a0874 Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Thu, 6 Jun 2024 22:22:58 +0300 Subject: refactor: Changed the method struct signatrue and added a new general Endpoint struct for better ergonomic api --- src/request.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/request.rs') diff --git a/src/request.rs b/src/request.rs index 7c8f43c..1858d5a 100644 --- a/src/request.rs +++ b/src/request.rs @@ -4,13 +4,13 @@ use crate::http_types::*; #[derive(Debug, Clone)] pub struct Request { - pub method: Method, + pub endpoint: Endpoint, pub headers: Option, body: Option, } impl Request { - fn new(method: Method, headers: Headers, body: String) -> Self { + fn new(method: Endpoint, headers: Headers, body: String) -> Self { let headers = if headers.0.len() == 0 { None } else { @@ -18,7 +18,7 @@ impl Request { }; let body = if body.is_empty() { None } else { Some(body) }; Request { - method, + endpoint: method, headers, body, } @@ -28,8 +28,8 @@ impl Request { self.headers.as_ref().unwrap().0.get(&key.to_string()) } - pub fn method(&self) -> &Method { - &self.method + pub fn endpoint(&self) -> &Endpoint { + &self.endpoint } pub fn headers(&self) -> &Option { @@ -46,7 +46,7 @@ impl From> for Request { match &value[..] { [request_line, headers @ .., body] => { let (method, headers, body) = - (Method::from(*request_line), Headers::from(headers), body); + (Endpoint::from(*request_line), Headers::from(headers), body); if let Some(content_length) = headers.0.get("Content-Length") { let content_length = content_length .parse::() @@ -65,7 +65,7 @@ impl From> for Request { impl<'a> Into for Request { fn into(self) -> String { - let method = String::from(self.method); + let method = String::from(self.endpoint); let (method, endpoint) = method.split_once(" ").unwrap(); let status_line = format!("{} {} HTTP/1.1", method, endpoint); let headers = self @@ -82,7 +82,7 @@ impl<'a> Into for Request { impl Into for &Request { fn into(self) -> String { - let method = String::from(self.method.clone()); + let method = String::from(self.endpoint.clone()); let (method, endpoint) = method.split_once(" ").unwrap(); let status_line = format!("{} {} HTTP/1.1", method, endpoint); let headers = self -- cgit v1.2.3