Merge pull request #54 from jaredly/fix-api-cors

allow OPTIONS requests for api endpoints (to enable CORS)
This commit is contained in:
Min RK 2015-05-08 11:45:44 -07:00
commit c5fe672d65
3 changed files with 25 additions and 2 deletions

View File

@ -48,7 +48,7 @@ class MainKernelHandler(IPythonHandler):
class KernelHandler(IPythonHandler):
SUPPORTED_METHODS = ('DELETE', 'GET')
SUPPORTED_METHODS = ('DELETE', 'GET', 'OPTIONS')
@web.authenticated
@json_errors
@ -66,6 +66,12 @@ class KernelHandler(IPythonHandler):
self.set_status(204)
self.finish()
@web.authenticated
@json_errors
def options(self, kernel_id):
self.set_header('Access-Control-Allow-Headers', 'accept, content-type')
self.finish()
class KernelActionHandler(IPythonHandler):
@ -83,6 +89,12 @@ class KernelActionHandler(IPythonHandler):
self.write(json.dumps(model))
self.finish()
@web.authenticated
@json_errors
def options(self, kernel_id, action):
self.set_header('Access-Control-Allow-Headers', 'accept, content-type')
self.finish()
class ZMQChannelsHandler(AuthenticatedZMQStreamHandler):

View File

@ -41,7 +41,7 @@ def kernelspec_model(handler, name):
return d
class MainKernelSpecHandler(IPythonHandler):
SUPPORTED_METHODS = ('GET',)
SUPPORTED_METHODS = ('GET', 'OPTIONS')
@web.authenticated
@json_errors
@ -61,6 +61,11 @@ class MainKernelSpecHandler(IPythonHandler):
self.set_header("Content-Type", 'application/json')
self.finish(json.dumps(model))
@web.authenticated
@json_errors
def options(self):
self.finish()
class KernelSpecHandler(IPythonHandler):
SUPPORTED_METHODS = ('GET',)

View File

@ -65,6 +65,12 @@ class SessionRootHandler(IPythonHandler):
self.set_status(201)
self.finish(json.dumps(model, default=date_default))
@web.authenticated
@json_errors
def options(self):
self.set_header('Access-Control-Allow-Headers', 'accept, content-type')
self.finish()
class SessionHandler(IPythonHandler):
SUPPORTED_METHODS = ('GET', 'PATCH', 'DELETE')