Last active
April 26, 2022 20:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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