Add a default OPTIONS handler for wsgi (#2301)

When a browser makes a CORS request, it often makes a 'preflight'
options request in order to make sure the resource is valid, and that
it has the right CORS access. This adds a default OPTIONS handler for
all views. If a view needs to customize the OPTIONS handler for some
reason, it's free to, but this way CORS will work.
pull/2305/head
Josh Wright 2016-06-14 22:44:12 -04:00 committed by Paulus Schoutsen
parent 65750f667b
commit 3fcc07af04
1 changed files with 4 additions and 0 deletions

View File

@ -443,3 +443,7 @@ class HomeAssistantView(object):
return self.Response(wrap_file(request.environ, fil), return self.Response(wrap_file(request.environ, fil),
mimetype=mimetype, direct_passthrough=True) mimetype=mimetype, direct_passthrough=True)
def options(self, request):
"""Default handler for OPTIONS (necessary for CORS preflight)."""
return self.Response('', status=200)