Add proxy option to config and prepare the requests with it - toot - Unnamed re… | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit a18df271fef4d221601d1b5e707010f06bba2c79 | |
parent c6b1d913707e9a107b44537e1f67dac73d82fe72 | |
Author: Christian Kellermann <[email protected]> | |
Date: Wed, 31 Jan 2018 14:22:05 +0100 | |
Add proxy option to config and prepare the requests with it | |
Diffstat: | |
toot/config.py | 18 ++++++++++++++++++ | |
toot/http.py | 3 ++- | |
2 files changed, 20 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/toot/config.py b/toot/config.py | |
@@ -45,6 +45,7 @@ def make_config(path): | |
"apps": apps, | |
"users": users, | |
"active_user": active_user, | |
+ "proxy" : {}, | |
} | |
print_out("Creating config file at <blue>{}</blue>".format(path)) | |
@@ -174,3 +175,20 @@ def activate_user(config, user): | |
config['active_user'] = user_id(user) | |
return config | |
+ | |
+@modify_config | |
+def set_proxy(config, proxy): | |
+ config['proxy'] = proxy | |
+ | |
+ return config | |
+ | |
+@modify_config | |
+def delete_proxy(config): | |
+ config['proxy'] = None | |
+ | |
+ return config | |
+ | |
+def get_proxy(): | |
+ config = load_config() | |
+ | |
+ return config['proxy'] | |
diff --git a/toot/http.py b/toot/http.py | |
@@ -1,12 +1,13 @@ | |
from requests import Request, Session | |
from toot.exceptions import NotFoundError, ApiError | |
from toot.logging import log_request, log_response | |
- | |
+from toot import config | |
def send_request(request, allow_redirects=True): | |
log_request(request) | |
with Session() as session: | |
+ session.proxies.update(config.get_proxy()) | |
prepared = session.prepare_request(request) | |
response = session.send(prepared, allow_redirects=allow_redirects) | |