-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upstream: Forward Content-Type from upstream if we don't already have one #835
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
/charon/getDataset?prefix=/groups/blab/sars-like-cov
showsContent-Type: application/json; charset=utf-8
on preview app (it doesn't on next.nextstrain.org)
… 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>
6ebc34d
to
7abc6a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - small changes like this are important and help keep the behaviour of the two APIs closer together.
/* 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"] : []), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upstream content-type is 'application/json'
however we are converting this to 'application/json; charset=utf-8'
. In practice, I don't think clients care about charsets for JSON, but my understanding is that it shouldn't be there (see page 11 of rfc8259).
This is automagically added by express so I'm guessing it's something we will live with:
res.set({'Content-Type': 'application/json'})
console.log(res.get("Content-Type")) // application/json; charset=utf-8
but I want to point this out here as our code to copy upstream headers over to the response will not just copy them but modify them.
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
Checklist