From 9de25c540464e95d1b67f1df1055b5013f5c3b41 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 18 May 2026 12:54:16 +0200 Subject: [PATCH] :bug: Fix incorrect content-type on doc endpoint response (#9681) The /api/main/doc endpoint was returning HTML content with a text/plain content-type header instead of text/html. This caused browsers to render the response as plain text. Added content-type: text/html; charset=utf-8 header to the response in the doc handler and added a regression test to verify the fix. Closes #9680 Signed-off-by: Andrey Antukh --- backend/src/app/rpc/doc.clj | 1 + backend/test/backend_tests/rpc_doc_test.clj | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backend/src/app/rpc/doc.clj b/backend/src/app/rpc/doc.clj index 611be93b15..62dffae23f 100644 --- a/backend/src/app/rpc/doc.clj +++ b/backend/src/app/rpc/doc.clj @@ -96,6 +96,7 @@ context (assoc @context :param-style pstyle)] {::yres/status 200 + ::yres/headers {"content-type" "text/html; charset=utf-8"} ::yres/body (-> (io/resource template) (tmpl/render context))}))) (fn [_] diff --git a/backend/test/backend_tests/rpc_doc_test.clj b/backend/test/backend_tests/rpc_doc_test.clj index 964ed57b6a..82c0dc28ff 100644 --- a/backend/test/backend_tests/rpc_doc_test.clj +++ b/backend/test/backend_tests/rpc_doc_test.clj @@ -12,10 +12,12 @@ [app.common.schema :as sm] [app.common.schema.generators :as sg] [app.common.schema.test :as smt] + [app.config :as cf] [app.rpc :as-alias rpc] [app.rpc.doc :as rpc.doc] [backend-tests.helpers :as th] - [clojure.test :as t])) + [clojure.test :as t] + [yetti.response :as-alias yres])) (t/use-fixtures :once th/state-init) @@ -31,6 +33,17 @@ false))) {:num 15})) - - +(t/deftest doc-handler-returns-html-content-type + (with-redefs [cf/flags #{:backend-api-doc}] + (let [methods (::rpc/methods th/*system*) + handler (#'rpc.doc/handler :methods methods + :label "main" + :entrypoint "http://localhost/api/main/methods" + :openapi "http://localhost/api/main/doc/openapi" + :template "app/templates/main-api-doc.tmpl") + request {} + response (handler request)] + (t/is (= 200 (::yres/status response))) + (t/is (= "text/html; charset=utf-8" + (get-in response [::yres/headers "content-type"]))))))