Add Auth Token to RuntimeEndpoint (#162)

This commit is contained in:
Srinivas Billa
2024-02-08 04:07:31 +00:00
committed by GitHub
parent b1a3a454ee
commit 405f26b00b
2 changed files with 18 additions and 9 deletions

View File

@@ -88,13 +88,18 @@ class HttpResponse:
return self.resp.status
def http_request(url, json=None, stream=False):
def http_request(url, json=None, stream=False, auth_token=None):
"""A faster version of requests.post with low-level urllib API."""
if stream:
return requests.post(url, json=json, stream=True)
headers = {
"Content-Type": "application/json",
"Authentication": f"Bearer {auth_token}"
}
return requests.post(url, json=json, stream=True, headers=headers)
else:
req = urllib.request.Request(url)
req.add_header("Content-Type", "application/json; charset=utf-8")
req.add_header("Authentication", f"Bearer {auth_token}")
if json is None:
data = None
else: