pyvec / elsa

Helper module for hosting Frozen-Flask based websites on GitHub pages
Other
28 stars 49 forks source link

Filename extension of 'api.geojson' (type application/octet-stream) does not match Content-Type: application/json #58

Closed honzajavorek closed 6 years ago

honzajavorek commented 6 years ago

Elsa is not able to recognize a correct media type for GeoJSON. What is the solution / workaround to this? Whatever I do in my code, Elsa will still consider .geojson files as application/octet-stream.

honzajavorek commented 6 years ago

Workaround is to serve it with .json 😞

hroncok commented 6 years ago

I think it's the mime thing that reports it as application/octet-stream. The proper long term solution would be to send a PR to freedesktop's shared mine info.

encukou commented 6 years ago

Does GitHub Pages serve the .json extension as geojson? If yes, I wonder what mapping they use. Elsa should use it as well.

On Sat, Sep 8, 2018, 11:44 Honza Javorek notifications@github.com wrote:

Elsa is not able to recognize a correct media type for GeoJSON. What is the solution / workaround to this? Whatever I do in my code, Elsa will still consider .geojson files as application/octet-stream.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pyvec/elsa/issues/58, or mute the thread https://github.com/notifications/unsubscribe-auth/AASfSmaoxh1ZB894XiXZEuFL_oZk0FXWks5uY5GKgaJpZM4WfzRa .

hroncok commented 6 years ago

Frozen-Flask uses the mimetypes module from Python.

This is what I get:

>>> import mimetypes
>>> mimetypes.guess_type('g.geojson')
('application/geo+json', None)

Is this a macOS only thing again? What do you get on macOS?

encukou commented 6 years ago

mimetypes is OS-specific – it uses `/etc/mime.types', '/etc/httpd/mime.types' etc :(

Ideally, Elsa would use GitHub's mapping. However, the Frozen-Flask warnings currently seem hardcoded for what Python (e.g. local SimpleHTTPServer) would use.

For now maybe Elsa could skip the checks on MacOS? Or on non-Linux?

hroncok commented 6 years ago

I was wondering if brew installing shared-mime-info would make the macOS mimetypes more comprehensive. However as I recently updated to a non yet released Fedora version, there is a mishmash of the kernel version and the VirtualBox kernel module version so I cannot try it right now. Was about to guide @honzajavorek trough the test, but wanted to get the output of mimetypes.guess_type('g.geojson') on macOS as is.

encukou commented 6 years ago

I have a Mac user next to me :) The output is (None, None).

hroncok commented 6 years ago

Assuming the python is installed via homebrew, does installing shared-mime-info change that?

encukou commented 6 years ago

It's not homebrew. I guess we need @honzajavorek now.

hroncok commented 6 years ago

Hehe. Anyway does installing shared-mime-info form homebrew change that (even if python is compiled form source/whatnot)?

honzajavorek commented 6 years ago

I installed shared-mime-info by brew and no Python on my machine produces anything else than None, None

On Mon, Sep 10, 2018 at 6:21 PM Miro Hrončok notifications@github.com wrote:

Hehe. Anyway does installing shared-mime-info form homebrew change that (even if python is compiled form source/whatnot)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pyvec/elsa/issues/58#issuecomment-419972411, or mute the thread https://github.com/notifications/unsubscribe-auth/AARTMQaxy5a48NplpdoqdFtKCcdPNJ0yks5uZpFrgaJpZM4WfzRa .

hroncok commented 6 years ago

And if you run update-mime-database $HOME/.local/share/mime?

hroncok commented 6 years ago

Or maybe sudo update-mime-database /usr/local/share/mime or something like that? I cannot realy get hands on now.

hroncok commented 6 years ago

Maybe this won't help at all. Apparently, Python's mimetypes look into files in mimetypes.knownfiles and shared-mime-info does not modify that.

I have application/geo+json geojson in /etc/mime.types and macOS apparently does not have that in such file.

Elsa or Frozen-Flask could in theory supply it's own mime.types override file. But that seems a bit overcomplicated.

hroncok commented 6 years ago

As an immediate workaround, you can use mimetypes.add_type in the projects where this bites you.

# macOS doesn't know this, so we supply our own override
mimetypes.add_type('application/geo+json', '.geojson')

This could also be used instead of https://github.com/pyvec/pyvec.org/blob/96c6bf0764ec47c9b1738ad5c0109f38c2eccfbf/pyvecorg/views.py#L22

hroncok commented 6 years ago

Does GitHub Pages serve the .json extension as geojson?

$ http https://python.cz/static/data/business.geojson
HTTP/1.1 200 OK
...
Content-Type: application/geo+json
...
honzajavorek commented 6 years ago

The workaround in https://github.com/pyvec/elsa/issues/58#issuecomment-420065000 helps! Thanks!