|
1 | | -import mimetypes |
2 | 1 | import json |
3 | 2 |
|
4 | 3 | from jupyter_server.base.handlers import JupyterHandler |
@@ -37,42 +36,18 @@ async def get(self): |
37 | 36 | self.write({"server_processes": data}) |
38 | 37 |
|
39 | 38 |
|
40 | | -# FIXME: Should be a StaticFileHandler subclass |
41 | | -class IconHandler(JupyterHandler): |
42 | | - """ |
43 | | - Serve launcher icons |
44 | | - """ |
| 39 | +# Took it from JupyterHub LogoHandler |
| 40 | +class IconHandler(web.StaticFileHandler): |
| 41 | + """A singular handler for serving the icon.""" |
45 | 42 |
|
46 | | - def initialize(self, icons): |
47 | | - """ |
48 | | - icons is a dict of titles to paths |
49 | | - """ |
50 | | - self.icons = icons |
| 43 | + def get(self): |
| 44 | + return super().get('') |
51 | 45 |
|
52 | | - async def get(self, name): |
53 | | - if name not in self.icons: |
54 | | - raise web.HTTPError(404) |
55 | | - path = self.icons[name] |
56 | | - |
57 | | - # Guess mimetype appropriately |
58 | | - # Stolen from https://github.com/tornadoweb/tornado/blob/b399a9d19c45951e4561e6e580d7e8cf396ef9ff/tornado/web.py#L2881 |
59 | | - mime_type, encoding = mimetypes.guess_type(path) |
60 | | - if encoding == "gzip": |
61 | | - content_type = "application/gzip" |
62 | | - # As of 2015-07-21 there is no bzip2 encoding defined at |
63 | | - # http://www.iana.org/assignments/media-types/media-types.xhtml |
64 | | - # So for that (and any other encoding), use octet-stream. |
65 | | - elif encoding is not None: |
66 | | - content_type = "application/octet-stream" |
67 | | - elif mime_type is not None: |
68 | | - content_type = mime_type |
69 | | - # if mime_type not detected, use application/octet-stream |
70 | | - else: |
71 | | - content_type = "application/octet-stream" |
72 | | - |
73 | | - with open(self.icons[name]) as f: |
74 | | - self.write(f.read()) |
75 | | - self.set_header("Content-Type", content_type) |
| 46 | + @classmethod |
| 47 | + def get_absolute_path(cls, root, path): |
| 48 | + """We only serve one file, ignore relative path""" |
| 49 | + import os |
| 50 | + return os.path.abspath(root) |
76 | 51 |
|
77 | 52 |
|
78 | 53 | class ServersAPIHandler(JupyterHandler): |
|
0 commit comments