Skip to content

Instantly share code, notes, and snippets.

@mrts
Last active April 26, 2022 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrts/2eefdf0f992f0f0e2269308fc6486011 to your computer and use it in GitHub Desktop.
Save mrts/2eefdf0f992f0f0e2269308fc6486011 to your computer and use it in GitHub Desktop.
A simple Python HTTP proxy that forwards all requests to download.cypress.io to enable Cypress download from NPM behind a Nexus proxy.
"""
A simple Python HTTP proxy that forwards all requests to download.cypress.io
to enable Cypress download from NPM behind a Nexus proxy.
This is to work around Nexus proxy limitations, see
- https://issues.sonatype.org/browse/NEXUS-22887 and
- https://issues.sonatype.org/browse/NEXUS-22889.
Requires Python 3.
How to run:
python3 -m venv venv
. venv/bin/activate
pip install requests
python3 cypress-proxy.py
See https://stackoverflow.com/a/62643730/258772 if you want to run the script as a daemon.
"""
from http.server import HTTPServer, SimpleHTTPRequestHandler
from io import BytesIO
import requests
PORT = 8000
PLATFORM = "win32"
ARCH = "x64"
class Proxy(SimpleHTTPRequestHandler):
def do_GET(self):
url = f"https://download.cypress.io{self.path}?platform={PLATFORM}&arch={ARCH}"
print(f"Proxying request to {url}")
response = requests.get(url)
self.copyfile(BytesIO(response.content), self.wfile)
def run():
server_address = ('', PORT)
httpd = HTTPServer(server_address, Proxy)
print(f"Cypress proxy running on port {PORT}")
httpd.serve_forever()
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment