def request_good(request):
def _new_fn(url: str, *, method: str = "GET", headers: dict = None, body: str = None):
# Get the unique signature for the Query
url_signature = "%s_ok" % make_url_signature(url,
method=method,
headers=headers,
body=body)
response = request.config.cache.get(url_signature, None)
# If response is not cached
if not response:
# Get and store a GOOD requests
raw_response = requests.request(url=url, method=method, headers=headers, data=body)
response = Response(status_code=raw_response.status_code,
headers=dict(raw_response.headers),
cookies=raw_response.cookies,
reason=raw_response.reason,
body=raw_response.text)
request.config.cache.set(url_signature, response.dump_json)
else:
# Recover response from cached info
response = Response.build_from_json(**response)
return response
return _new_fn
评论列表
文章目录