add ap date format and fix default client for header val
This commit is contained in:
parent
6ae253b40d
commit
a731490af4
|
@ -33,7 +33,6 @@ class httpClient:
|
|||
def _fetch(self, url, headers={}, method='GET', data=None, cached=True):
|
||||
cached_data = self.cache.fetch(url)
|
||||
#url = url.split('#')[0]
|
||||
#print(url)
|
||||
|
||||
if cached and cached_data:
|
||||
logging.debug(f'Returning cached data for {url}')
|
||||
|
@ -61,7 +60,8 @@ class httpClient:
|
|||
resp = self.client.request(method, url, headers=headers)
|
||||
|
||||
except Exception as e:
|
||||
raise ConnectionError(f'Failed to fetch url: {e}')
|
||||
logging.debug(f'Failed to fetch url: {e}')
|
||||
return
|
||||
|
||||
if cached:
|
||||
logging.debug(f'Caching {url}')
|
||||
|
@ -90,20 +90,19 @@ class httpClient:
|
|||
'''
|
||||
Return the body as a dict if it's json
|
||||
'''
|
||||
|
||||
headers = kwargs.get('headers')
|
||||
|
||||
if not headers:
|
||||
kwargs['headers'] = {}
|
||||
|
||||
kwargs['headers'].update({'Accept': 'application/json'})
|
||||
|
||||
resp = self._fetch(*args, **kwargs)
|
||||
|
||||
try:
|
||||
data = json.loads(resp.data.decode())
|
||||
|
||||
except Exception as e:
|
||||
print(resp.data.decode())
|
||||
logging.debug(f'Failed to load json: {e}')
|
||||
return
|
||||
|
||||
|
@ -149,11 +148,11 @@ def ValidateSignature(headers, method, path, client=None, agent=None):
|
|||
headers (dict): All of the headers to be used to check a signature. The signature header must be included too
|
||||
method (str): The http method used in relation to the headers
|
||||
path (str): The path of the request in relation to the headers
|
||||
client (pool object): Specify a urllib3 pool to use for fetching the actor. optional
|
||||
client (pool object): Specify a httpClient to use for fetching the actor. optional
|
||||
agent (str): User agent used for fetching actor data. optional
|
||||
'''
|
||||
|
||||
client = httpClient(agent) if not client else client
|
||||
client = httpClient(agent=agent) if not client else client
|
||||
headers = {k.lower(): v for k,v in headers.items()}
|
||||
|
||||
try:
|
||||
|
|
|
@ -38,8 +38,12 @@ def randomgen(chars=20):
|
|||
return ''.join(random.choices(string.ascii_letters + string.digits, k=chars))
|
||||
|
||||
|
||||
def formatUTC(timestamp=None):
|
||||
def formatUTC(timestamp=None, ap=False):
|
||||
date = datetime.fromtimestamp(timestamp) if timestamp else datetime.utcnow()
|
||||
|
||||
if ap:
|
||||
return date.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
|
||||
return date.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue