Skip to content

Conversation

elliotcm
Copy link
Contributor

@elliotcm elliotcm commented Oct 24, 2022

The Rack specification states that header values must be a String instance (or array thereof).

When setting up the content-type header based on the file extension, send_stream assigns the whole
Mime::Type object, instead of its String
representation.

This change ensures that all three ways of setting the content-type header (implicit via extension,
implicit via a symbol, and explicit via a string)
all result in a String instance being assigned as the header's value.

Motivation / Background

This Pull Request has been created because other libraries (in this case specifically https://github.com/DFE-Digital/dfe-analytics and its use of BigQuery) assume that header values will be strings per the rack spec.

Detail

This Pull Request changes the behaviour of send_stream when it is inferring a content-type from the file extension, so that it assigns a String instance as the header value rather than a Mime::Type instance.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
  • CI is passing.

The Rack specification[1] states that header values
must be a `String` instance (or array thereof).

When setting up the content-type header based on the
file extension, `send_stream` assigns the whole
`Mime::Type` object, instead of its `String`
representation.

This change ensures that all three ways of setting
the content-type header (implicit via extension,
implicit via a symbol, and explicit via a string)
all result in a `String` instance being assigned as
the header's value.

[1] https://github.com/rack/rack/blob/0a62f75eeee8fbf14e87a92d458a4428382e3504/SPEC.rdoc#label-The+Headers
@rails-bot rails-bot bot added the actionpack label Oct 24, 2022
@skipkayhil
Copy link
Member

Looks great! Thanks @elliotcm

@skipkayhil skipkayhil added the ready PRs ready to merge label Oct 25, 2022
@elliotcm
Copy link
Contributor Author

@skipkayhil It looks like the build failed for an unrelated reason. Is there a way to re-run it?

@skipkayhil
Copy link
Member

It looks like the build failed for an unrelated reason. Is there a way to re-run it?

I wouldn't worry about it, commiters will see that they are unrelated.

@rafaelfranca rafaelfranca merged commit 7c38258 into rails:main Jan 18, 2023
rafaelfranca added a commit that referenced this pull request Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionpack ready PRs ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants