Whoops text/json isn't a real content type

This commit is contained in:
august kline 2024-08-31 18:04:01 -04:00
parent 266c16b9a8
commit 6be8f81fa9
1 changed files with 10 additions and 11 deletions

View File

@ -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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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<String>) -> 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())