Files
Corsy/core/requester.py

24 lines
819 B
Python
Raw Permalink Normal View History

2019-12-13 18:13:21 +05:30
import urllib3
2019-11-24 21:12:10 +05:30
import requests
2020-08-21 11:10:58 +05:30
from core.colors import bad
2019-11-24 21:12:10 +05:30
2019-12-13 18:13:21 +05:30
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
2020-08-21 11:10:58 +05:30
# Added better error handling.
# Added verbose options.
2019-12-15 18:12:56 +08:00
def requester(url, scheme, headers, origin):
2021-01-28 18:21:49 +05:30
headers['Origin'] = origin
2020-08-21 11:10:58 +05:30
try:
2021-11-14 00:10:22 +00:00
response = requests.get(url, headers=headers, verify=False)
headers = response.headers
for key, value in headers.items():
2020-08-21 11:10:58 +05:30
if key.lower() == 'access-control-allow-origin':
2021-11-14 00:10:22 +00:00
return headers
2020-08-21 11:10:58 +05:30
except requests.exceptions.RequestException as e:
if 'Failed to establish a new connection' in str(e):
2021-01-28 16:34:37 +05:30
print ('%s %s is unreachable' % (bad, url))
2020-08-21 15:58:22 +05:30
elif 'requests.exceptions.TooManyRedirects:' in str(e):
2021-01-28 16:34:37 +05:30
print ('%s %s has too many redirects' % (bad, url))
2021-01-28 18:21:49 +05:30
return {}