summaryrefslogtreecommitdiff
path: root/src/types/response.rs
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2023-01-28 02:51:34 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2023-01-28 02:51:34 -0500
commitc01b8b8c90fa762f25bf52437611643e3ca16e5a (patch)
treec93293c5c074a03808cdd4b85cdf6001f2f17dd6 /src/types/response.rs
parentrusty boio finished (diff)
downloadxssbook-c01b8b8c90fa762f25bf52437611643e3ca16e5a.tar.gz
xssbook-c01b8b8c90fa762f25bf52437611643e3ca16e5a.tar.bz2
xssbook-c01b8b8c90fa762f25bf52437611643e3ca16e5a.zip
fix rerendering logout button, console page
Diffstat (limited to 'src/types/response.rs')
-rw-r--r--src/types/response.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/types/response.rs b/src/types/response.rs
index bea3406..72c1334 100644
--- a/src/types/response.rs
+++ b/src/types/response.rs
@@ -28,7 +28,7 @@ impl ResponseCode {
}
}
- pub fn msg(self, msg: &str) -> Response {
+ pub fn text(self, msg: &str) -> Response {
(self.code(), msg.to_owned()).into_response()
}
@@ -40,17 +40,25 @@ impl ResponseCode {
res
}
+ pub fn html(self, json: &str) -> Response {
+ let mut res = (self.code(), json.to_owned()).into_response();
+ res.headers_mut().insert(
+ HeaderName::from_static("content-type"), HeaderValue::from_static("text/html"),
+ );
+ res
+ }
+
pub async fn file(self, path: &str) -> Result<Response> {
if path.chars().position(|c| c == '.' ).is_none() {
- return Err(ResponseCode::BadRequest.msg("Folders cannot be served"));
+ return Err(ResponseCode::BadRequest.text("Folders cannot be served"));
}
let path = format!("public{}", path);
let svc = ServeFile::new(path);
let Ok(mut res) = svc.oneshot(Request::new(Body::empty())).await else {
- return Err(ResponseCode::InternalServerError.msg("Error wile fetching file"));
+ return Err(ResponseCode::InternalServerError.text("Error wile fetching file"));
};
if res.status() != StatusCode::OK {
- return Err(ResponseCode::NotFound.msg("File not found"));
+ return Err(ResponseCode::NotFound.text("File not found"));
}
*res.status_mut() = self.code();
Ok(res.into_response())