Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.
/ pulp Public archive

Attempt to guess the MIME type of content served with xsendfile. #2396

Merged
merged 1 commit into from
Feb 8, 2016

Conversation

jeremycline
Copy link
Contributor

This is mostly for the benefit of browsers, since the default MIME
type Django uses is text/html which causes the browser to attempt to
render RPMs and such instead of downloading them.

closes #1627

@@ -68,7 +69,13 @@ def x_send(path):
:rtype: django.http.HttpResponse
"""
if os.access(path, os.R_OK):
reply = HttpResponse()
content_type = mimetypes.guess_type(path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could use a library like libmagic to determine the file type (which will be much more accurate), but I was hesitant to introduce a new dependency. The downside to this method is that if the file suffix is wrong/missing (like the listing files which are text of some variety) the 'application/octet-stream' is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, there is a Python binding to libmagic that seems to "come with" Fedora last I checked. I'm not sure about ELs though. Also, it's not documented, and I spent quite a lot of time trying to figure out how to use its API.

Oh, and there are no less than three Python libraries that are bindings to libmagic that share the same name but do not have the same API. If we depend on one of them, it will be difficult to express which one we need in our setup.py which could be bad if we ever want to work in Debian, which by the way uses a different one than Fedora uses.

This is mostly for the benefit of browsers, since the default MIME
type Django uses is text/html which causes the browser to attempt to
render RPMs and such instead of downloading them.

closes pulp#1627
jeremycline added a commit that referenced this pull request Feb 8, 2016
Attempt to guess the MIME type of content served with xsendfile.
@jeremycline jeremycline merged commit 57113b6 into pulp:master Feb 8, 2016
@jeremycline jeremycline deleted the set-content-type-xsendfile branch February 8, 2016 20:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants