From 59360d9cd6cee33a82fcb5ff2b618b2101acf37c Mon Sep 17 00:00:00 2001 From: nazeh Date: Tue, 6 Aug 2024 10:57:36 +0300 Subject: [PATCH] feat(homeserver): return list results as json newline --- pubky-homeserver/src/routes/public.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pubky-homeserver/src/routes/public.rs b/pubky-homeserver/src/routes/public.rs index 26d270e..a99f633 100644 --- a/pubky-homeserver/src/routes/public.rs +++ b/pubky-homeserver/src/routes/public.rs @@ -4,7 +4,7 @@ use axum::{ body::{Body, Bytes}, debug_handler, extract::{Path, Query, State}, - http::StatusCode, + http::{header, Response, StatusCode}, response::IntoResponse, RequestExt, Router, }; @@ -92,14 +92,18 @@ pub async fn get( params.get("cursor").map(|cursor| cursor.into()), )?; - return Ok(vec.join("\n").into()); + return Ok(Response::builder() + .status(StatusCode::OK) + .header(header::CONTENT_TYPE, "application/json") + .body(Body::from(vec.join("\n"))) + .unwrap()); } // TODO: Enable streaming match state.db.get_blob(public_key, path.as_str()) { Err(error) => Err(error)?, - Ok(Some(bytes)) => Ok(bytes), + Ok(Some(bytes)) => Ok(Response::builder().body(Body::from(bytes)).unwrap()), Ok(None) => Err(Error::with_status(StatusCode::NOT_FOUND)), } }