Skip to content

fix Content-Type header set for SVG files #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
4 changes: 3 additions & 1 deletion jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,9 @@ def update_api_activity(self):
def finish(self, *args, **kwargs):
"""Finish an API response."""
self.update_api_activity()
self.set_header("Content-Type", "application/json")
# prevent overriding Content-Type set in GatewayResourceHandler
if "Content-Type" not in self._headers:
self.set_header("Content-Type", "application/json")
return super().finish(*args, **kwargs)

def options(self, *args, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,10 @@ async def test_gateway_get_named_kernelspec(init_gateway, jp_fetch):
kspec_foo = json.loads(r.body.decode("utf-8"))
assert kspec_foo.get("name") == "kspec_foo"

r = await jp_fetch("kernelspecs", "kspec_foo", "hi", method="GET")
r = await jp_fetch("kernelspecs", "kspec_foo", "logo-64x64.png", method="GET")
assert r.code == 200
assert r.body == b"foo"
assert r.headers["content-type"] == "image/png"

with pytest.raises(tornado.httpclient.HTTPClientError) as e:
await jp_fetch("api", "kernelspecs", "no_such_spec", method="GET")
Expand Down