From 3fcc07af0484c917d8b6a33c0d21336ee1da7a19 Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Tue, 14 Jun 2016 22:44:12 -0400 Subject: [PATCH] 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. --- homeassistant/components/http.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homeassistant/components/http.py b/homeassistant/components/http.py index 1ec5703c5a3..3ccf92daea2 100644 --- a/homeassistant/components/http.py +++ b/homeassistant/components/http.py @@ -443,3 +443,7 @@ class HomeAssistantView(object): return self.Response(wrap_file(request.environ, fil), mimetype=mimetype, direct_passthrough=True) + + def options(self, request): + """Default handler for OPTIONS (necessary for CORS preflight).""" + return self.Response('', status=200)