Show More
@@ -24,7 +24,10 class FilesHandler(IPythonHandler): | |||
|
24 | 24 | |
|
25 | 25 | path, name = os.path.split(path) |
|
26 | 26 | model = cm.get_model(name, path) |
|
27 | ||
|
27 | ||
|
28 | if self.get_argument("download", False): | |
|
29 | self.set_header('Content-Disposition','attachment; filename="%s"' % name) | |
|
30 | ||
|
28 | 31 | if model['type'] == 'notebook': |
|
29 | 32 | self.set_header('Content-Type', 'application/json') |
|
30 | 33 | else: |
@@ -32,8 +35,6 class FilesHandler(IPythonHandler): | |||
|
32 | 35 | if cur_mime is not None: |
|
33 | 36 | self.set_header('Content-Type', cur_mime) |
|
34 | 37 | |
|
35 | self.set_header('Content-Disposition','attachment; filename="%s"' % name) | |
|
36 | ||
|
37 | 38 | if model['format'] == 'base64': |
|
38 | 39 | b64_bytes = model['content'].encode('ascii') |
|
39 | 40 | self.write(base64.decodestring(b64_bytes)) |
@@ -112,7 +112,7 define([ | |||
|
112 | 112 | notebook_path, |
|
113 | 113 | notebook_name |
|
114 | 114 | ); |
|
115 | window.open(url); | |
|
115 | window.open(url + '?download=1'); | |
|
116 | 116 | }); |
|
117 | 117 | |
|
118 | 118 | this.element.find('#print_preview').click(function () { |
@@ -98,7 +98,23 class FilesTest(NotebookTestBase): | |||
|
98 | 98 | self.assertEqual(r.status_code, 200) |
|
99 | 99 | self.assertEqual(r.headers['content-type'], 'text/plain') |
|
100 | 100 | self.assertEqual(r.text, 'foobar') |
|
101 | ||
|
102 | def test_download(self): | |
|
103 | nbdir = self.notebook_dir.name | |
|
104 | base = self.base_url() | |
|
105 | ||
|
106 | text = 'hello' | |
|
107 | with open(pjoin(nbdir, 'test.txt'), 'w') as f: | |
|
108 | f.write(text) | |
|
109 | ||
|
110 | r = requests.get(url_path_join(base, 'files', 'test.txt')) | |
|
111 | disposition = r.headers.get('Content-Disposition', '') | |
|
112 | self.assertNotIn('attachment', disposition) | |
|
101 | 113 | |
|
114 | r = requests.get(url_path_join(base, 'files', 'test.txt') + '?download=1') | |
|
115 | disposition = r.headers.get('Content-Disposition', '') | |
|
116 | self.assertIn('attachment', disposition) | |
|
117 | self.assertIn('filename="test.txt"', disposition) | |
|
102 | 118 | |
|
103 | 119 | def test_old_files_redirect(self): |
|
104 | 120 | """pre-2.0 'files/' prefixed links are properly redirected""" |
General Comments 0
You need to be logged in to leave comments.
Login now