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

fix(gateway): ensure directory listings have Content-Type text/html #7330

Merged
merged 2 commits into from May 20, 2020

Conversation

Lekensteyn
Copy link
Contributor

Files already have an explicit Content-Type set. Be sure to do this for
directory listings as well to avoid a fallback to autodetection in
net/http. That fallback fails when a ResponseWriter is installed that
performs compression.

@welcome
Copy link

welcome bot commented May 18, 2020

Thank you for submitting this PR!
A maintainer will be here shortly to review it.
We are super grateful, but we are also overloaded! Help us by making sure that:

  • The context for this PR is clear, with relevant discussion, decisions
    and stakeholders linked/mentioned.

  • Your contribution itself is clear (code comments, self-review for the
    rest) and in its best form. Follow the code contribution
    guidelines

    if they apply.

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
Next steps:

  • A maintainer will triage and assign priority to this PR, commenting on
    any missing things and potentially assigning a reviewer for high
    priority items.

  • The PR gets reviews, discussed and approvals as needed.

  • The PR is merged by maintainers when it has been approved and comments addressed.

We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution.
We are very grateful for your contribution!

@Stebalien
Copy link
Member

How exactly did you run into this problem?

@Lekensteyn
Copy link
Contributor Author

One of the configured corehttp.ServeOptions in our gateway added gzip compression if the client supports it via Accept-Encoding. That resulted in empty Content-Type headers when compression is enabled, and for some reason it resulted in a reverse proxy displaying the HTML index as plain text.

@Stebalien
Copy link
Member

Ah, I see.

@Stebalien
Copy link
Member

Stebalien commented May 19, 2020 via email

Report a consistent status code for HEAD requests that end up in a
redirect.
Files already have an explicit Content-Type set. Be sure to do this for
directory listings as well to avoid a fallback to autodetection in
net/http. That fallback fails when a ResponseWriter is installed that
performs compression.
@Lekensteyn Lekensteyn force-pushed the fix/dir-listing-content-type branch from 4885c94 to d4952f2 Compare May 20, 2020 13:21
@Lekensteyn
Copy link
Contributor Author

There is only one error case now, namely when the directory contents cannot be read. In that special case, the content-type will be text/plain while the HEAD request will return text/html. I'd say that is acceptable.

Since the previous version, #4233 got merged which introduces a new edge case: if ipfs-404.html is present, the directory index is not shown. However even for that case, text/html is appropriate.

@Stebalien Stebalien merged commit 2380343 into ipfs:master May 20, 2020
@Stebalien
Copy link
Member

Thanks!

@Stebalien Stebalien mentioned this pull request May 26, 2020
77 tasks
hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
…tent-type

fix(gateway): ensure directory listings have Content-Type text/html

This commit was moved from ipfs/kubo@2380343
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.

None yet

2 participants