From 6be8f81fa99273c33e1336aeabf5e930f559254f Mon Sep 17 00:00:00 2001 From: august kline Date: Sat, 31 Aug 2024 18:04:01 -0400 Subject: [PATCH] Whoops text/json isn't a real content type --- src/main.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 07ecdbb..ef477e0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ use axum::{ }; use base64::{engine::general_purpose::STANDARD, Engine}; -use serde::Deserialize; use tower::{buffer::BufferLayer, limit::rate::RateLimitLayer, ServiceBuilder}; #[tokio::main] @@ -53,12 +52,6 @@ fn app() -> Router { .route("/:command", get(command)) } -#[derive(Deserialize, Debug)] -struct Manpage { - command: String, - html: String, -} - #[derive(Debug)] enum ManserveErr { NotFound, @@ -107,7 +100,7 @@ async fn command(Path(command): Path) -> impl IntoResponse { let json = format!("{{\"command\": \"{command}\", \"html\": \"{html}\"}}"); ( StatusCode::OK, - [(header::CONTENT_TYPE, "text/json")], + [(header::CONTENT_TYPE, "application/json")], json.into_response(), ) } @@ -116,7 +109,7 @@ async fn command(Path(command): Path) -> impl IntoResponse { let json = format!("{{\"command\": \"{command}\", \"error\": \"Could not find the requested command\"}}"); ( StatusCode::NOT_FOUND, - [(header::CONTENT_TYPE, "text/json")], + [(header::CONTENT_TYPE, "application/json")], json.into_response(), ) } @@ -124,7 +117,7 @@ async fn command(Path(command): Path) -> impl IntoResponse { let json = format!("{{\"command\": \"{command}\", \"error\": \"The server could not complete the request\"}}"); ( StatusCode::INTERNAL_SERVER_ERROR, - [(header::CONTENT_TYPE, "text/json")], + [(header::CONTENT_TYPE, "application/json")], json.into_response(), ) } @@ -132,7 +125,7 @@ async fn command(Path(command): Path) -> impl IntoResponse { let json = format!("{{\"command\": \"{command}\", \"error\": \"There was invalid utf-8 in the request\"}}"); ( StatusCode::BAD_REQUEST, - [(header::CONTENT_TYPE, "text/json")], + [(header::CONTENT_TYPE, "application/json")], json.into_response(), ) } @@ -144,6 +137,7 @@ async fn command(Path(command): Path) -> impl IntoResponse { mod tests { use axum::{body::Body, http::Request}; use http_body_util::BodyExt; + use serde::Deserialize; use tower::Service; use super::*; @@ -175,6 +169,11 @@ mod tests { #[tokio::test] async fn man_ls() { + #[derive(Deserialize, Debug)] + struct Manpage { + command: String, + html: String, + } let mut app = app(); let res = app .call(Request::builder().uri("/ls").body(Body::default()).unwrap())