Skip to content

Commit

Permalink
Fix pywwt on notebook >=5.7.6
Browse files Browse the repository at this point in the history
Version 5.7.6 of the Jupyter notebook module adds a new security feature
related to the HTTP content types
(jupyter/notebook#4467 (comment)). It
breaks pywwt because pywwt has not been returning valid MIME types (AKA
content types) from its internal Jupyter server.

From looking at the main `notebook` implementation, it seems that the correct
approach is to use the `mimetypes` module to get the right value to put in the
Content-Type header, so let's go ahead and do that.

Closes WorldWideTelescope#191.
  • Loading branch information
pkgw committed Mar 28, 2019
1 parent 9099fae commit f02b554
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pywwt/jupyter_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import json
import mimetypes
from hashlib import md5
from tornado import web
from notebook.utils import url_path_join
Expand Down Expand Up @@ -33,6 +34,9 @@ def get(self, filename):
else:
raise web.HTTPError(404)

# Do our best to set an appropriate Content-Type.
self.set_header('Content-Type', mimetypes.guess_type(filename)[0])

with open(path, 'rb') as f:
content = f.read()

Expand Down

0 comments on commit f02b554

Please sign in to comment.