Merge pull request #2402 from gnestor/utf-8

Specify `charset=UTF-8` when serving non-base64 files
This commit is contained in:
Kyle Kelley 2017-04-26 11:48:33 -07:00 committed by GitHub
commit 469b1c84be
2 changed files with 5 additions and 3 deletions

View File

@ -46,13 +46,15 @@ class FilesHandler(IPythonHandler):
self.set_header('Content-Type', 'application/x-ipynb+json') self.set_header('Content-Type', 'application/x-ipynb+json')
else: else:
cur_mime = mimetypes.guess_type(name)[0] cur_mime = mimetypes.guess_type(name)[0]
if cur_mime is not None: if cur_mime == 'text/plain':
self.set_header('Content-Type', 'text/plain; charset=UTF-8')
elif cur_mime is not None:
self.set_header('Content-Type', cur_mime) self.set_header('Content-Type', cur_mime)
else: else:
if model['format'] == 'base64': if model['format'] == 'base64':
self.set_header('Content-Type', 'application/octet-stream') self.set_header('Content-Type', 'application/octet-stream')
else: else:
self.set_header('Content-Type', 'text/plain') self.set_header('Content-Type', 'text/plain; charset=UTF-8')
if include_body: if include_body:
if model['format'] == 'base64': if model['format'] == 'base64':

View File

@ -95,7 +95,7 @@ class FilesTest(NotebookTestBase):
r = self.request('GET', 'files/test.txt') r = self.request('GET', 'files/test.txt')
self.assertEqual(r.status_code, 200) self.assertEqual(r.status_code, 200)
self.assertEqual(r.headers['content-type'], 'text/plain') self.assertEqual(r.headers['content-type'], 'text/plain; charset=UTF-8')
self.assertEqual(r.text, 'foobar') self.assertEqual(r.text, 'foobar')
def test_download(self): def test_download(self):