Whoops text/json isn't a real content type
This commit is contained in:
parent
266c16b9a8
commit
6be8f81fa9
21
src/main.rs
21
src/main.rs
|
@ -15,7 +15,6 @@ use axum::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||||
use serde::Deserialize;
|
|
||||||
use tower::{buffer::BufferLayer, limit::rate::RateLimitLayer, ServiceBuilder};
|
use tower::{buffer::BufferLayer, limit::rate::RateLimitLayer, ServiceBuilder};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
@ -53,12 +52,6 @@ fn app() -> Router {
|
||||||
.route("/:command", get(command))
|
.route("/:command", get(command))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
struct Manpage {
|
|
||||||
command: String,
|
|
||||||
html: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ManserveErr {
|
enum ManserveErr {
|
||||||
NotFound,
|
NotFound,
|
||||||
|
@ -107,7 +100,7 @@ async fn command(Path(command): Path<String>) -> impl IntoResponse {
|
||||||
let json = format!("{{\"command\": \"{command}\", \"html\": \"{html}\"}}");
|
let json = format!("{{\"command\": \"{command}\", \"html\": \"{html}\"}}");
|
||||||
(
|
(
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(header::CONTENT_TYPE, "text/json")],
|
[(header::CONTENT_TYPE, "application/json")],
|
||||||
json.into_response(),
|
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\"}}");
|
let json = format!("{{\"command\": \"{command}\", \"error\": \"Could not find the requested command\"}}");
|
||||||
(
|
(
|
||||||
StatusCode::NOT_FOUND,
|
StatusCode::NOT_FOUND,
|
||||||
[(header::CONTENT_TYPE, "text/json")],
|
[(header::CONTENT_TYPE, "application/json")],
|
||||||
json.into_response(),
|
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\"}}");
|
let json = format!("{{\"command\": \"{command}\", \"error\": \"The server could not complete the request\"}}");
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
[(header::CONTENT_TYPE, "text/json")],
|
[(header::CONTENT_TYPE, "application/json")],
|
||||||
json.into_response(),
|
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\"}}");
|
let json = format!("{{\"command\": \"{command}\", \"error\": \"There was invalid utf-8 in the request\"}}");
|
||||||
(
|
(
|
||||||
StatusCode::BAD_REQUEST,
|
StatusCode::BAD_REQUEST,
|
||||||
[(header::CONTENT_TYPE, "text/json")],
|
[(header::CONTENT_TYPE, "application/json")],
|
||||||
json.into_response(),
|
json.into_response(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -144,6 +137,7 @@ async fn command(Path(command): Path<String>) -> impl IntoResponse {
|
||||||
mod tests {
|
mod tests {
|
||||||
use axum::{body::Body, http::Request};
|
use axum::{body::Body, http::Request};
|
||||||
use http_body_util::BodyExt;
|
use http_body_util::BodyExt;
|
||||||
|
use serde::Deserialize;
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -175,6 +169,11 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn man_ls() {
|
async fn man_ls() {
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct Manpage {
|
||||||
|
command: String,
|
||||||
|
html: String,
|
||||||
|
}
|
||||||
let mut app = app();
|
let mut app = app();
|
||||||
let res = app
|
let res = app
|
||||||
.call(Request::builder().uri("/ls").body(Body::default()).unwrap())
|
.call(Request::builder().uri("/ls").body(Body::default()).unwrap())
|
||||||
|
|
Loading…
Reference in New Issue