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

Include mime.types file and use it for WebUI Content-Types #1950

Open
wants to merge 1 commit into
base: master
from

Conversation

@ValdikSS
Copy link

@ValdikSS ValdikSS commented Apr 2, 2019

Python 2.7 on Windows loads known MIME types from registry, which is
not always up-to-date. For example, it causes issue with webp images:
http://127.0.0.1:43110/Talk.ZeroNetwork.bit/?Topic:1554160326_131Seivv6aH8vnohPmYPcPwPfZ1a5ubMMs

The mime.types file has been merged from Fedora's /etc/mime.types and
https://s-randomfiles.s3.amazonaws.com/mime/allMimeTypes.txt

Python 2.7 on Windows loads known MIME types from registry, which is
not always up-to-date. For example, it causes issue with webp images:
http://127.0.0.1:43110/Talk.ZeroNetwork.bit/?Topic:1554160326_131Seivv6aH8vnohPmYPcPwPfZ1a5ubMMs

The mime.types file has been merged from Fedora's /etc/mime.types and
https://s-randomfiles.s3.amazonaws.com/mime/allMimeTypes.txt
@HelloZeroNet
Copy link
Owner

@HelloZeroNet HelloZeroNet commented Apr 3, 2019

I think it would be better more predictable not use mimetypes module, but add a simple module that parse handle mimetypes queries and parse the data file.

@ValdikSS
Copy link
Author

@ValdikSS ValdikSS commented Apr 3, 2019

@HelloZeroNet, why? mimetypes is a small module, it's included in standard Python library and already bundled&used in ZeroNet.

@imachug
Copy link
Contributor

@imachug imachug commented Jul 1, 2019

@HelloZeroNet Any progress on this?

@HelloZeroNet
Copy link
Owner

@HelloZeroNet HelloZeroNet commented Jul 1, 2019

I still think it would be easier/faster to include a small list of known popular filetypes without using the mimetypes module. For example: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types

@filips123
Copy link
Contributor

@filips123 filips123 commented Jul 3, 2019

@HelloZeroNet What if program first checks some common MIME types from your list. If none of them matches, the program also checks mimetypes module (because it contains more types). If it still doesn't match, it uses application/octet-stream.

@HelloZeroNet
Copy link
Owner

@HelloZeroNet HelloZeroNet commented Jul 3, 2019

It's also possible, but I think its better if it's does not depends on system settings, but works the same way on for every client. So if there is any problem related to content-type, then we can find the problem and reproduce it easier.

@ValdikSS
Copy link
Author

@ValdikSS ValdikSS commented Jul 3, 2019

@HelloZeroNet Are you aware that mimetypes module just loads my list and parses it, without using system mime types? Are you still want to replace it with a custom one? I don't understand the reason.

@HelloZeroNet
Copy link
Owner

@HelloZeroNet HelloZeroNet commented Jul 3, 2019

I usually try to avoid using packages if I can do the same with a few lines of code to avoid unwanted side effects.
Eg for in this case mimetypes.guess_type("any.html.xz")[0] returns text/html, but probably we want to serve it xz file as browsers won't be able to display the xz file content as html
Other problem could be if any other module uses the mimetypes before our mimtes.init called, then it won't be inited from our file.

@ValdikSS
Copy link
Author

@ValdikSS ValdikSS commented Jul 4, 2019

Unfortunately I don't have much spare time recently.
I propose the following: use this modification for Python 2 version, and for Python 3 version I (or somebody else) will make a proper mime types implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.