Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/source/server-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ the following keys:
Set to True (default) to make an entry in the launchers. Set to False to have no
explicit entry.
2. **icon_path**
Full path to an svg icon that could be used with a launcher. Currently only used by the
JupyterLab launcher, when category is "Notebook" (default) or "Console". Only text-based icon
formats, such as SVG, are supported. Using binary-based formats like PNG or JPEG will
result in an empty icon being displayed in kernels.
Full path to an icon file that could be used with a launcher (for example, `.svg` or `.png`).
Currently only used by the JupyterLab launcher, when category is "Notebook" (default) or "Console".
3. **title**
Title to be used for the launcher entry. Defaults to the name of the server if missing.
4. **path_info**
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server_proxy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ async def get(self, name):
else:
content_type = "application/octet-stream"

with open(self.icons[name]) as f:
with open(self.icons[name], "rb") as f:
self.write(f.read())
self.set_header("Content-Type", content_type)
Binary file added tests/resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions tests/resources/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/resources/jupyter_server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ def my_env():
"python-http": {
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
},
"python-http-icon-svg": {
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"launcher_entry": {
"icon_path": _get_path("icon.svg"),
},
},
"python-http-icon-png": {
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"launcher_entry": {
"icon_path": _get_path("icon.png"),
},
},
"python-http-abs": {
"command": [sys.executable, _get_path("httpinfo.py"), "--port={port}"],
"absolute_url": True,
Expand Down
32 changes: 32 additions & 0 deletions tests/test_proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,35 @@ def test_server_proxy_redirect_location_header_absolute_url(
# Backend returns whatever it wants, proxy doesn't rewrite it
# In this case, backend adds trailing slash to the full path it received
assert location == f"/python-redirect-abs/abc/?token={TOKEN}"


def test_server_proxy_icon_handler_svg(
a_server_port_and_token: Tuple[int, str],
) -> None:
PORT, TOKEN = a_server_port_and_token

r = request_get(PORT, "/server-proxy/icon/python-http-icon-svg", TOKEN)
assert r.code == 200

content_type = r.headers.get("Content-Type")
assert content_type is not None
assert content_type.startswith("image/svg")

body = r.read().decode("utf-8")
assert "<svg" in body


def test_server_proxy_icon_handler_png(
a_server_port_and_token: Tuple[int, str],
) -> None:
PORT, TOKEN = a_server_port_and_token

r = request_get(PORT, "/server-proxy/icon/python-http-icon-png", TOKEN)
assert r.code == 200

content_type = r.headers.get("Content-Type")
assert content_type is not None
assert content_type.startswith("image/png")

body = r.read()
assert body.startswith(b"\x89PNG\r\n\x1a\n")