Skip to content

fix: Set correct Content-Type when serving assets#136

Closed
sbernauer wants to merge 1 commit into
mainfrom
fix/assets-content-type
Closed

fix: Set correct Content-Type when serving assets#136
sbernauer wants to merge 1 commit into
mainfrom
fix/assets-content-type

Conversation

@sbernauer
Copy link
Copy Markdown
Member

Users have reported problems using either Chrome, Edge or Safari getting the error message

failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.

The root cause was that we set the Content-Type header twice, once to application/octet-stream and the second to text/javascript. With this fix only a single (correct) Content-Type header is sent.

Thanks @Techassi for the help!

Description

Please add a description here. This will become the commit message of the merge request later.

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes
# Author
- [ ] Changes are OpenShift compatible
- [ ] CRD changes approved
- [ ] Helm chart can be installed and deployed operator works
- [ ] Integration tests passed (for non trivial changes)
# Reviewer
- [ ] Code contains useful comments
- [ ] (Integration-)Test cases added
- [ ] Documentation added or updated
- [ ] Changelog updated
- [ ] Cargo.toml only contains references to git tags (not specific commits or branches)
# Acceptance
- [ ] Feature Tracker has been updated
- [ ] Proper release label has been added

Once the review is done, comment bors r+ (or bors merge) to merge. Further information

Users have reported problems using either Chrome, Edge or Safari getting the error message

failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/octet-stream". Strict MIME type checking is enforced for module scripts per HTML spec.

The root cause was that we set the Content-Type header twice, once to application/octet-stream and the second to text/javascript.
With this fix only a single (correct) Content-Type header is sent.
Comment on lines +23 to +24
async fn asset(mut headers: HeaderMap, Path(name): Path<String>) -> impl IntoResponse {
headers.insert(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't do what you want it to. The HeaderMap argument isn't some base set of headers defined by the framework, but the headers sent by the client. What this PR actually does is to reflect any headers sent by the user back at them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can test this yourself: curl 'http://localhost:8000/ui/assets/index-1272d2e9.js' -H 'foo: bar' -D- -o /dev/null | grep foo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Close enough ^^
Good catch, thx!

Comment on lines +20 to +22
/// Adds (or replaces) the Content-Type header with the type of the served asset.
/// So far only javascript and css are supported, for all the other types
/// `application/octet-stream` will be used.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a detail of the function, but not its primary purpose. This should be either a subsection of the doccomment, or a regular comment inside of the function.

@sbernauer
Copy link
Copy Markdown
Member Author

Superseded by #137

@sbernauer sbernauer deleted the fix/assets-content-type branch November 3, 2023 08:48
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.

2 participants