Skip to content

Instantly share code, notes, and snippets.

@cdrage
Created August 9, 2023 16:24
Show Gist options
  • Save cdrage/07220d49e99ed54e0f5f0e3e6ab74758 to your computer and use it in GitHub Desktop.
Save cdrage/07220d49e99ed54e0f5f0e3e6ab74758 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from http.server import SimpleHTTPRequestHandler, HTTPServer
class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path.startswith("/v2/"):
self.send_response(401)
self.send_header('Date', 'Tue, 18 Jul 2023 15:43:13 GMT')
self.send_header('Server', 'Nexus/3.52.0-01 (OSS)')
self.send_header('X-Content-Type-Options', 'nosniff')
self.send_header('Content-Security-Policy', 'sandbox allow-forms allow-modals allow-popups allow-presentation allow-scripts allow-top-navigation')
self.send_header('X-XSS-Protection', '1; mode=block')
self.send_header('Docker-Distribution-Api-Version', 'registry/2.0')
self.send_header('Content-Type', 'application/json')
self.send_header('Content-Length', '113')
self.send_header('WWW-Authenticate', 'BASIC realm="Sonatype Nexus Repository Manager"')
self.end_headers()
self.wfile.write(b'{"error": "Unauthorized"}') # A simple JSON response
else:
super().do_GET()
if __name__ == "__main__":
PORT = 8000
httpd = HTTPServer(('0.0.0.0', PORT), CustomHTTPRequestHandler)
print(f"Serving on port {PORT}...")
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment