Skip to content

Commit

Permalink
Use proxy for external requests (#10008)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchamp authored Nov 21, 2024
1 parent dedebe7 commit 7549c41
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions openlibrary/plugins/openlibrary/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,32 @@ def setup_context_defaults():
context.defaults.update({'features': [], 'user': None, 'MAX_VISIBLE_BOOKS': 5})


def setup_requests():
logger.info("Setting up requests")

logger.info("Setting up proxy")
if infogami.config.get("http_proxy", ""):
os.environ['HTTP_PROXY'] = os.environ['http_proxy'] = infogami.config.get(
'http_proxy'
)
os.environ['HTTPS_PROXY'] = os.environ['https_proxy'] = infogami.config.get(
'http_proxy'
)
logger.info('Proxy environment variables are set')
else:
logger.info("No proxy configuration found")

logger.info("Setting up proxy bypass")
if infogami.config.get("no_proxy_addresses", []):
no_proxy = ",".join(infogami.config.get("no_proxy_addresses"))
os.environ['NO_PROXY'] = os.environ['no_proxy'] = no_proxy
logger.info('Proxy bypass environment variables are set')
else:
logger.info("No proxy bypass configuration found")

logger.info("Requests set up")


def setup():
from openlibrary.plugins.openlibrary import (
sentry,
Expand Down Expand Up @@ -1421,6 +1447,7 @@ def setup():

setup_context_defaults()
setup_template_globals()
setup_requests()


setup()

0 comments on commit 7549c41

Please sign in to comment.