Skip to content
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

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

tsibley
Copy link
Member

@tsibley tsibley commented Apr 22, 2024

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

  • Checks pass

@tsibley tsibley requested a review from a team April 22, 2024 19:25
@nextstrain-bot nextstrain-bot temporarily deployed to nextstrain-s-trs-charon-bfi0tp April 22, 2024 19:25 Inactive
@jameshadfield jameshadfield self-assigned this Apr 22, 2024
Copy link
Member

@victorlin victorlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… 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>
@tsibley tsibley force-pushed the trs/charon-content-type branch from 6ebc34d to 7abc6a3 Compare April 22, 2024 21:59
@tsibley tsibley temporarily deployed to nextstrain-s-trs-charon-bfi0tp April 22, 2024 21:59 Inactive
Copy link
Member

@jameshadfield jameshadfield left a 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"] : []),
Copy link
Member

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.

@tsibley tsibley merged commit 2b12ed8 into master Apr 23, 2024
4 checks passed
@tsibley tsibley deleted the trs/charon-content-type branch April 23, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants