Skip to content

Commit

Permalink
upstream: Forward Content-Type from upstream if we don't already have…
Browse files Browse the repository at this point in the history
… one

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.

¹ <#832>
  • Loading branch information
tsibley committed Apr 22, 2024
1 parent b031d11 commit 7abc6a3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/upstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 7abc6a3

Please sign in to comment.