diff --git a/Cargo.toml b/Cargo.toml index ba40f89..f1ba79d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "http" -version = "0.1.4" +version = "0.1.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/response.rs b/src/response.rs index 6f40dbf..fee8ff6 100644 --- a/src/response.rs +++ b/src/response.rs @@ -33,12 +33,16 @@ impl Default for HTTPResponse { fn default() -> Self { HTTPResponse { status_line: HTTPStatusLine::default(), - body: json::parse(r#"{}"#).unwrap(), + body: json::parse("{}").unwrap(), } } } impl HTTPResponse { + pub fn get_status_code(&self) -> HTTPStatusCode { + self.status_line.get_status_code() + } + pub fn as_500(message: Option) -> Self { let mut response = Self::default(); diff --git a/src/status.rs b/src/status.rs index 776eded..03881e3 100644 --- a/src/status.rs +++ b/src/status.rs @@ -1,6 +1,6 @@ use crate::HTTPVersion; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone, Copy)] pub enum HTTPStatusCode { Http200, Http400, @@ -21,6 +21,7 @@ impl Into for HTTPStatusCode { } } + pub struct HTTPStatusLine { version: HTTPVersion, status_code: HTTPStatusCode, @@ -44,7 +45,12 @@ impl Into for HTTPStatusLine { } impl HTTPStatusLine { + pub fn get_status_code(&self) -> HTTPStatusCode { + self.status_code + } + pub fn set_status_code(&mut self, code: HTTPStatusCode) { self.status_code = code; } } +