From 9376c328fbacb4415086a714286eccd48c68c621 Mon Sep 17 00:00:00 2001 From: valkyrie_pilot Date: Wed, 19 Jun 2024 08:47:57 -0600 Subject: [PATCH] Rename content types --- src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6dce57b..ee0c9dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -459,11 +459,11 @@ pub struct ErrorTemplate { nonce: String, } -static HTML_CTYPE: HeaderValue = HeaderValue::from_static("text/html;charset=utf-8"); +static HTML_CONTENT_TYPE: HeaderValue = HeaderValue::from_static("text/html;charset=utf-8"); pub struct Json(pub T); -static JSON_CTYPE: HeaderValue = HeaderValue::from_static("application/json;charset=utf-8"); +static JSON_CONTENT_TYPE: HeaderValue = HeaderValue::from_static("application/json;charset=utf-8"); fn infallible_json_serialize(data: &T) -> Vec { serde_json::to_vec_pretty(data).unwrap_or_else(|_| { @@ -478,7 +478,7 @@ impl IntoResponse for Json { let body = infallible_json_serialize(&self.0); ( StatusCode::INTERNAL_SERVER_ERROR, - [(CONTENT_TYPE, JSON_CTYPE.clone())], + [(CONTENT_TYPE, JSON_CONTENT_TYPE.clone())], body, ) .into_response() @@ -500,11 +500,13 @@ async fn error_middleware( let error = failure.to_string(); let status = resp.status(); if json { - resp.headers_mut().insert(CONTENT_TYPE, JSON_CTYPE.clone()); + resp.headers_mut() + .insert(CONTENT_TYPE, JSON_CONTENT_TYPE.clone()); let error = ErrorSerialization { error }; (status, Json(infallible_json_serialize(&error))).into_response() } else { - resp.headers_mut().insert(CONTENT_TYPE, HTML_CTYPE.clone()); + resp.headers_mut() + .insert(CONTENT_TYPE, HTML_CONTENT_TYPE.clone()); let error = ErrorTemplate { error, bd: state.bust_dir, @@ -522,8 +524,8 @@ pub struct Png(pub Vec); impl IntoResponse for Png { fn into_response(self) -> Response { - static PNG_CTYPE: HeaderValue = HeaderValue::from_static("image/png"); - let headers = [(CONTENT_TYPE, PNG_CTYPE.clone())]; + static PNG_CONTENT_TYPE: HeaderValue = HeaderValue::from_static("image/png"); + let headers = [(CONTENT_TYPE, PNG_CONTENT_TYPE.clone())]; (headers, self.0).into_response() } }