diff --git a/.gitignore b/.gitignore index ec8fbb301ae..af2fb1769b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ config/* !config/home-assistant.conf.default homeassistant/components/http/www_static/polymer/bower_components/* +homeassistant/components/http/www_static/polymer/build.htm # There is not a better solution afaik.. !config/custom_components diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 6c06283a336..b5bf8900356 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -190,6 +190,7 @@ class RequestHandler(BaseHTTPRequestHandler): PATHS = [ # debug interface ('GET', URL_ROOT, '_handle_get_root'), + ('POST', URL_ROOT, '_handle_get_root'), # /api - for validation purposes ('GET', rem.URL_API, '_handle_get_api'), @@ -236,6 +237,9 @@ class RequestHandler(BaseHTTPRequestHandler): """ Does some common checks and calls appropriate method. """ url = urlparse(self.path) + if url.path.startswith('/api/'): + self.use_json = True + # Read query input data = parse_qs(url.query) @@ -248,14 +252,19 @@ class RequestHandler(BaseHTTPRequestHandler): if content_length: body_content = self.rfile.read(content_length).decode("UTF-8") - try: - data.update(json.loads(body_content)) - except ValueError: - self.server.logger.exception( - "Exception parsing JSON: {}".format(body_content)) - self.send_response(HTTP_UNPROCESSABLE_ENTITY) - return + if self.use_json: + try: + data.update(json.loads(body_content)) + except ValueError: + self.server.logger.exception( + "Exception parsing JSON: {}".format(body_content)) + + self.send_response(HTTP_UNPROCESSABLE_ENTITY) + return + else: + data.update({key: value[-1] for key, value in + parse_qs(body_content).items()}) api_password = self.headers.get(rem.AUTH_HEADER) @@ -265,9 +274,6 @@ class RequestHandler(BaseHTTPRequestHandler): if '_METHOD' in data: method = data.pop('_METHOD') - if url.path.startswith('/api/'): - self.use_json = True - # Var to keep track if we found a path that matched a handler but # the method was different path_matched_but_not_method = False @@ -342,22 +348,19 @@ class RequestHandler(BaseHTTPRequestHandler): self.wfile.write(( "" "