-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Use browser's default application open handler for non-dangerous MIME types #20720
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Matt Hamilton <m@tthamilton.com>
Codecov Report
@@ Coverage Diff @@
## main #20720 +/- ##
==========================================
- Coverage 46.93% 46.91% -0.02%
==========================================
Files 981 981
Lines 136275 136280 +5
==========================================
- Hits 63961 63942 -19
- Misses 64463 64484 +21
- Partials 7851 7854 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This may need more logic like in ping @silverwind, you worked on this some days ago. |
Firefox preference uses the "Content-Type" header to find whether the resource will be downloaded or directly viewed. I'll love to have this feature, and not only for PDF, for JPG, mp3, txt.... Using |
But then the question is if the package registry is the correct place for these files. I may be better to put them into issues in a repo? |
Yes, we should set a proper content-type, you can use the existing |
If you'd like me to give implementing this a go, I'll need a few days to get around to this and better familiarize myself with the existing code (you referenced above). Re: security implications only a whitelisted subset of MIME types should be served with Thanks for all your input! |
For my use-case, I'm using CI to generate a PDF document that is built from the contents of the repo at a fixed point in time (each commit). The use-case is the same as building a binary blob from the source code in the repo, I just happen to be building a PDF instead of an executable. |
Yes, that's how the logic in
Can you answer? Is this change about view raw? |
I don't know what "view raw" means in this context. Currently, all generic package downloads are sent with By making this change, clicking a file in a generic package would respect the browser's open handler, which may be the browser itself (PDF, mp3, webm, etc.). Using PDF as an example, if the browser is the default handler, clicking a PDF in a generic package should open the PDF in a new tab (as opposed to downloading the file and requiring an additional click to view). |
This behavior is not exclusive to FireFox: Chrome behavior is also to download the file, not open, if the |
Is this PR still relevant? |
This changes PDF downloads to not be displayed inline in the browser (or preferred application) rather than being saved as a download. The current implementation requires multiple clicks to open PDFs included in
generic
packages.There is no existing issue for this, and I have not created one.
Notably, this is not the way GitHub behaves, but is the way I wish GitHub behaved.
Additionally, this adds quotes to the filename parameter per MSDN:
I have not tested this code or checked if this change has any (security?) consequences for usages of this function outside of serving
generic
-type package files. A MIME-type check (as opposed to this implementation's file extension check) may or may not be necessary.