in mozilla_schema_generator/generic_ping.py [0:0]
def _get_json_str(url: str) -> str:
if GenericPing._present_in_cache(url):
return GenericPing._retrieve_from_cache(url)
headers = {}
if url.startswith(GenericPing.probe_info_base_url):
# For probe-info-service requests, set the cache-control header to force
# google cloud cdn to bypass the cache
headers["Cache-Control"] = "no-cache"
r = requests.get(url, headers=headers, stream=True)
r.raise_for_status()
json_bytes = b""
try:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
json_bytes += chunk
except ValueError as e:
raise ValueError("Could not parse " + url) from e
final_json = json_bytes.decode(r.encoding or GenericPing.default_encoding)
GenericPing._add_to_cache(url, final_json)
return final_json