From bff0a6229154becd2db90aaffbac33e8c8c326e2 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 18 Aug 2023 15:41:23 -0400 Subject: [PATCH] Change response to impl IntoResponse. --- src/main.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7231af8..0438c54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,9 @@ #![feature(exit_status_error)] +use axum::http::header::CACHE_CONTROL; +use axum::http::HeaderMap; +use axum::response::IntoResponse; use axum::{http::StatusCode, routing::post, Json, Router}; -use owner_tree::{build_owner_tree, OwnerTree}; +use owner_tree::build_owner_tree; use parse::emacs_parse_org_document; use tower_http::services::{ServeDir, ServeFile}; @@ -20,18 +23,20 @@ async fn main() { axum::serve(listener, app).await.unwrap(); } -async fn parse_org_mode( - body: String, -) -> Result<(StatusCode, Json), (StatusCode, String)> { +async fn parse_org_mode(body: String) -> Result { _parse_org_mode(body) .await .map_err(|e| (StatusCode::BAD_REQUEST, e.to_string())) } -async fn _parse_org_mode( - body: String, -) -> Result<(StatusCode, Json), Box> { +async fn _parse_org_mode(body: String) -> Result> { let ast = emacs_parse_org_document(&body).await?; let owner_tree = build_owner_tree(body.as_str(), ast.as_str()).map_err(|e| e.to_string())?; Ok((StatusCode::OK, Json(owner_tree))) } + +fn no_cache_headers() -> HeaderMap { + let mut headers = HeaderMap::new(); + headers.insert(CACHE_CONTROL, "public, max-age=120".parse().unwrap()); + headers +}