From 7abc6a31a7c291a3e095eb4e5113be891ab8f3b3 Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Mon, 22 Apr 2024 12:19:25 -0700 Subject: [PATCH] upstream: Forward Content-Type from upstream if we don't already have one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example, our RESTful endpoints perform content negotiation and use the result to determine Content-Type (and also what to Accept in the request to upstream), but our Charon endpoints do not set Content-Type at all. Set it based on the upstream response in that situation. I noticed this bug (while investigating another issue¹) because the automatic compression middleware wasn't applying to the /charon/getDataset endpoint due to the lack of Content-Type. ¹ --- src/upstream.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/upstream.js b/src/upstream.js index 8a7102ee4..c98e999d2 100644 --- a/src/upstream.js +++ b/src/upstream.js @@ -234,6 +234,11 @@ async function proxyResponseBodyFromUpstream(req, res, upstreamReq) { * client can decode the body itself. */ ...(!upstreamReq.compress ? ["Content-Encoding"] : []), + + /* Forward Content-Type if our response doesn't already have a preferred + * type set (e.g. from prior content negotiation). + */ + ...(!res.get("Content-Type") ? ["Content-Type"] : []), ]; res.set(copyHeaders(upstreamRes.headers, forwardedUpstreamResHeaders));