From 0d889cb0b2f2f6a82b20d1180ebfc7aee4fb8ea5 Mon Sep 17 00:00:00 2001 From: Kishan Joshi Date: Sat, 20 Sep 2025 18:13:58 +0530 Subject: [PATCH] Add proxy envs (#1499) Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com> --- README.md | 3 +++ src/flaresolverr.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e1b974..142139b 100644 --- a/README.md +++ b/README.md @@ -266,6 +266,9 @@ This is the same as `request.get` but it takes one more param: |--------------------|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------| | LOG_LEVEL | info | Verbosity of the logging. Use `LOG_LEVEL=debug` for more information. | | LOG_HTML | false | Only for debugging. If `true` all HTML that passes through the proxy will be logged to the console in `debug` level. | +| PROXY_URL | none | URL for proxy. Will be overwritten by `request` or `sessions` proxy, if used. Example: `http://127.0.0.1:8080`. | +| PROXY_USERNAME | none | Username for proxy. Will be overwritten by `request` or `sessions` proxy, if used. Example: `testuser`. | +| PROXY_PASSWORD | none | Password for proxy. Will be overwritten by `request` or `sessions` proxy, if used. Example: `testpass`. | | CAPTCHA_SOLVER | none | Captcha solving method. It is used when a captcha is encountered. See the Captcha Solvers section. | | TZ | UTC | Timezone used in the logs and the web browser. Example: `TZ=Europe/London`. | | LANG | none | Language used in the web browser. Example: `LANG=en_GB`. | diff --git a/src/flaresolverr.py b/src/flaresolverr.py index 3596fe1..e29745f 100644 --- a/src/flaresolverr.py +++ b/src/flaresolverr.py @@ -13,6 +13,10 @@ from dtos import V1RequestBase import flaresolverr_service import utils +env_proxy_url = os.environ.get('PROXY_URL', None) +env_proxy_username = os.environ.get('PROXY_USERNAME', None) +env_proxy_password = os.environ.get('PROXY_PASSWORD', None) + class JSONErrorBottle(Bottle): """ @@ -50,7 +54,14 @@ def controller_v1(): """ Controller v1 """ - req = V1RequestBase(request.json) + data = request.json or {} + if (('proxy' not in data or not data.get('proxy')) and env_proxy_url is not None and (env_proxy_username is None and env_proxy_password is None)): + logging.info('Using proxy URL ENV') + data['proxy'] = {"url": env_proxy_url} + if (('proxy' not in data or not data.get('proxy')) and env_proxy_url is not None and (env_proxy_username is not None or env_proxy_password is not None)): + logging.info('Using proxy URL, username & password ENVs') + data['proxy'] = {"url": env_proxy_url, "username": env_proxy_username, "password": env_proxy_password} + req = V1RequestBase(data) res = flaresolverr_service.controller_v1_endpoint(req) if res.__error_500__: response.status = 500