tests: http client fixes
Correctly encode the query string. Use the query string for DELETE requests in addition to GET requests. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
5f96822c90
commit
d630b79e8b
|
@ -1,11 +1,12 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import json
|
import json
|
||||||
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPError
|
||||||
from tornado.httputil import HTTPHeaders
|
from tornado.httputil import HTTPHeaders
|
||||||
from tornado.escape import url_escape
|
from tornado.escape import url_escape
|
||||||
from typing import Dict, Any, Optional
|
from typing import Dict, Any, Optional
|
||||||
|
|
||||||
class HttpClient:
|
class HttpClient:
|
||||||
|
error = HTTPError
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
type: str = "http",
|
type: str = "http",
|
||||||
port: int = 7010
|
port: int = 7010
|
||||||
|
@ -30,16 +31,16 @@ class HttpClient:
|
||||||
method = method.upper()
|
method = method.upper()
|
||||||
body: Optional[str] = "" if method == "POST" else None
|
body: Optional[str] = "" if method == "POST" else None
|
||||||
if args:
|
if args:
|
||||||
if method == "GET":
|
if method in ["GET", "DELETE"]:
|
||||||
parts = []
|
parts = []
|
||||||
for key, val in args.items():
|
for key, val in args.items():
|
||||||
if isinstance(val, list):
|
if isinstance(val, list):
|
||||||
val = ",".join(val)
|
val = ",".join(val)
|
||||||
if val:
|
if val:
|
||||||
parts.append(f"{key}={val}")
|
parts.append(f"{url_escape(key)}={url_escape(val)}")
|
||||||
else:
|
else:
|
||||||
parts.append(key)
|
parts.append(url_escape(key))
|
||||||
qs = url_escape("&".join(parts))
|
qs = "&".join(parts)
|
||||||
url += "?" + qs
|
url += "?" + qs
|
||||||
else:
|
else:
|
||||||
body = json.dumps(args)
|
body = json.dumps(args)
|
||||||
|
|
Loading…
Reference in New Issue