This commit is contained in:
2018-10-11 18:53:51 -04:00
parent 07ba75d9d5
commit fc0d811740
3 changed files with 20 additions and 3 deletions
+2 -2
View File
@@ -173,9 +173,9 @@ class API:
# Support query/q in params.
if "query" in req.params:
return req.params["query"][0]
return req.params["query"]
if "q" in req.params:
return req.params["q"][0]
return req.params["q"]
# Otherwise, the request text is used (typical).
# TODO: Make some assertions about content-type here.
+9 -1
View File
@@ -19,6 +19,14 @@ from .status_codes import HTTP_200
# pass
def flatten(d):
for key, value in d.copy().items():
if len(value) == 1:
d[key] = value[0]
return d
class Request:
def __init__(self):
super().__init__()
@@ -34,7 +42,7 @@ class Request:
self.url = self._wz.base_url
self.full_path = self._wz.full_path
self.path = self._wz.path
self.params = parse_qs(self._wz.query_string.decode("utf-8"))
self.params = flatten(parse_qs(self._wz.query_string.decode("utf-8")))
self.query = self._wz.query_string.decode("utf-8")
self.raw = self._wz.stream
self.content = self._wz.get_data(cache=True, as_text=False)
+9
View File
@@ -177,3 +177,12 @@ def test_request_and_get(api):
r = api.session().get("http://;/")
assert "DEATH" in r.headers
assert "LIFE" in r.headers
def test_query_params(api):
@api.route("/")
def route(req, resp):
resp.media = {"params": req.params}
r = api.session().get("http://;/?q=q")
assert r.json()["params"] == {"q": "q"}