From 37ac9e3ab8cdba82cdc1e07206ca7d3001031870 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Mon, 8 Aug 2011 15:52:05 +0100 Subject: [PATCH] decluttering _parse_request_params method for QuantumController --- quantum/api/api_common.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/quantum/api/api_common.py b/quantum/api/api_common.py index 140a7c5b9..b3847bce2 100644 --- a/quantum/api/api_common.py +++ b/quantum/api/api_common.py @@ -38,7 +38,7 @@ class QuantumController(wsgi.Controller): for param in params: param_name = param['param-name'] param_value = None - # 1- parse request body + # Parameters are expected to be in request body only if req.body: des_body = self._deserialize(req.body, req.best_match_content_type()) @@ -50,22 +50,13 @@ class QuantumController(wsgi.Controller): LOG.error(line) raise exc.HTTPBadRequest(msg) param_value = data.get(param_name, None) - if not param_value: - # 2- parse request headers - # prepend param name with a 'x-' prefix - param_value = req.headers.get("x-" + param_name, None) - # 3- parse request query parameters - if not param_value: - try: - param_value = req.str_GET[param_name] - except KeyError: - #param not found - pass - if not param_value and param['required']: - msg = ("Failed to parse request. " + - "Parameter: " + param_name + " not specified") - for line in msg.split('\n'): - LOG.error(line) - raise exc.HTTPBadRequest(msg) + + # If the parameter wasn't found and it was required, return 400 + if not param_value and param['required']: + msg = ("Failed to parse request. " + + "Parameter: " + param_name + " not specified") + for line in msg.split('\n'): + LOG.error(line) + raise exc.HTTPBadRequest(msg) results[param_name] = param_value or param.get('default-value') return results -- 2.45.2