Commit 106e8a97 authored by juga's avatar juga
Browse files

requests: refactor, set session attributes

to their values instead of have to extra functions to call
in every request.
This also makes the code more clear.
parent c2b85b3f
......@@ -37,8 +37,8 @@ def timed_recv_from_server(session, dest, byte_range):
# - What other exceptions can this throw?
# - Do we have to read the content, or did requests already do so?
try:
requests_utils.get(
session, dest.url, headers=headers, verify=dest.verify)
# headers are merged with the session ones, not overwritten.
session.get(dest.url, headers=headers, verify=dest.verify)
except requests.exceptions.ConnectionError as e:
return False, e
except requests.exceptions.ReadTimeout as e:
......
......@@ -73,7 +73,7 @@ def connect_to_destination_over_circuit(dest, circ_id, session, cont, max_dl):
try:
# TODO:
# - What other exceptions can this throw?
head = requests_utils.head(session, dest.url, verify=dest.verify)
head = session.head(dest.url, verify=dest.verify)
except (requests.exceptions.ConnectionError,
requests.exceptions.ReadTimeout) as e:
return False, 'Could not connect to {} over circ {} {}: {}'.format(
......
......@@ -5,17 +5,9 @@ import sbws.util.stem as stem_utils
def make_session(controller, timeout):
s = requests.Session()
socks_info = stem_utils.get_socks_info(controller)
s.sbws_proxies = {
s.proxies = {
'http': 'socks5h://{}:{}'.format(*socks_info),
'https': 'socks5h://{}:{}'.format(*socks_info),
}
s.sbws_timeout = timeout
s.timeout = timeout
return s
def get(s, url, **kw):
return s.get(url, timeout=s.sbws_timeout, proxies=s.sbws_proxies, **kw)
def head(s, url, **kw):
return s.head(url, timeout=s.sbws_timeout, proxies=s.sbws_proxies, **kw)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment