From 89aac05d68042d6fc22782d125ae9850dee6b4b6 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 24 May 2021 22:29:13 +0200 Subject: [PATCH 1/2] Add preflight and delete option in sessions --- kernel_gateway/services/sessions/handlers.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel_gateway/services/sessions/handlers.py b/kernel_gateway/services/sessions/handlers.py index 0db38ae..4f3d7a0 100644 --- a/kernel_gateway/services/sessions/handlers.py +++ b/kernel_gateway/services/sessions/handlers.py @@ -27,6 +27,23 @@ def get(self): else: super(SessionRootHandler, self).get() +class SessionHandler(TokenAuthorizationMixin, + CORSMixin, + JSONErrorsMixin, + notebook_handlers.SessionHandler): + """Extends the notebook session handler with token auth, CORS, and + JSON errors. + """ + def set_default_headers(self): + self.set_header('Content-Type', 'application/json') + self.set_header('Access-Control-Allow-Origin', '*') + self.set_header('Access-Control-Allow-Headers', 'content-type') + self.set_header('Access-Control-Allow-Methods', 'DELETE') + + def options(self, **kwargs): + """Method for properly handling CORS pre-flight""" + self.finish() + default_handlers = [] for path, cls in notebook_handlers.default_handlers: if cls.__name__ in globals(): From 442ec700bd25e40e94efcb20d5f9f1aa1d5ecd47 Mon Sep 17 00:00:00 2001 From: Kevin Bates Date: Thu, 2 Mar 2023 14:21:16 -0800 Subject: [PATCH 2/2] Use configurables to set header values --- kernel_gateway/services/sessions/handlers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel_gateway/services/sessions/handlers.py b/kernel_gateway/services/sessions/handlers.py index 4f3d7a0..b5b81e1 100644 --- a/kernel_gateway/services/sessions/handlers.py +++ b/kernel_gateway/services/sessions/handlers.py @@ -36,9 +36,9 @@ class SessionHandler(TokenAuthorizationMixin, """ def set_default_headers(self): self.set_header('Content-Type', 'application/json') - self.set_header('Access-Control-Allow-Origin', '*') - self.set_header('Access-Control-Allow-Headers', 'content-type') - self.set_header('Access-Control-Allow-Methods', 'DELETE') + self.set_header('Access-Control-Allow-Origin', self.settings['kg_allow_origin']) + self.set_header('Access-Control-Allow-Headers', self.settings['kg_allow_headers']) + self.set_header('Access-Control-Allow-Methods', self.settings['kg_allow_methods']) def options(self, **kwargs): """Method for properly handling CORS pre-flight"""