Skip to content
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

Support hparams plugin via Tensorboard POST api handler. #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
53 changes: 53 additions & 0 deletions jupyter_tensorboard/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,59 @@ def get(self, name, path):
else:
raise web.HTTPError(404)

@web.authenticated
def post(self, name, path):

if path == "":
uri = self.request.path + "/"
if self.request.query:
uri += "?" + self.request.query
self.redirect(uri, permanent=True)
return

self.request.path = (
path if self.request.query
else "%s?%s" % (path, self.request.query))

manager = self.settings["tensorboard_manager"]
if name in manager:
tb_app = manager[name].tb_app
WSGIContainer(tb_app)(self.request)
else:
raise web.HTTPError(404)

def check_xsrf_cookie(self):
"""Expand xsrf check exception for POST requests.

Expand xsrf_cookie exceptions, normally only applied to GET and HEAD
requests, to POST requests for tensorboard api.

Provides support for hparams plugin, which uses POST to retrieve
experiment information but can't be trivially extended to include xsrf
information in these POST requests.

"""

try:
return super(TensorboardHandler, self).check_xsrf_cookie()
except web.HTTPError:
if self.request.method in {"GET", "POST", "HEAD"}:
# Consider Referer a sufficient cross-origin check for GET
# requests, mirrors logic in IPythonHandler.check_xsrf_cookie.
# Extended to POST for Tensorboard API.
if not self.check_referer():
referer = self.request.headers.get("Referer")
if referer:
msg = (
"Blocking Cross Origin request from {}."
.format(referer)
)
else:
msg = "Blocking request from unknown origin"
raise web.HTTPError(403, msg)
else:
raise


class TensorboardErrorHandler(IPythonHandler):
pass