Add demo upstream that echoes received headers
Browse files123456789101112131415161718192021222324252627282930313233343536#!/usr/bin/env python3"""Minimal upstream that echoes the request headers it received.
Used to make the reverse-proxy key injection observable: any request to/model-api/ is proxied here, and the JSON response shows the`Authorization` header nginx attached server-side."""import jsonfrom http.server import BaseHTTPRequestHandler, HTTPServer
HOST, PORT = "127.0.0.1", 5000
class EchoHandler(BaseHTTPRequestHandler): def _respond(self): payload = { "method": self.command, "path": self.path, "received_headers": {k: v for k, v in self.headers.items()}, "note": "Authorization here is injected by nginx, not by the client.", } body = json.dumps(payload, indent=2).encode() self.send_response(200) self.send_header("Content-Type", "application/json") self.send_header("Content-Length", str(len(body))) self.end_headers() self.wfile.write(body)
do_GET = do_POST = do_PUT = do_PATCH = do_DELETE = _respond
def log_message(self, *_args): pass
if __name__ == "__main__": HTTPServer((HOST, PORT), EchoHandler).serve_forever()demo_upstream.pyAdded+36