WSGI start_response, reading headers set
10:07 13 Jun 2026

Trying to find a way to read what headers have been set by the WSGI start_response object. We know they are stored somewhere as not transmitted until after the return statement, question is where are they stored and how can I access them?

Example code:

from wsgiref.simple_server import make_server
from wsgiref.headers import Headers

def hello_world_app(environ, start_response):
    status = "200 OK"  # HTTP Status
    headers = [("Content-type", "text/plain; charset=utf-8")]  # HTTP Headers
    start_response(status, headers)
    print("???") # <- read response header here that has been set by start_response
    return [b"Hello workld"]
environ.items()]

with make_server("", 8000, hello_world_app) as httpd:
    print("Serving on port 8000...")
    httpd.serve_forever()
python python-3.x wsgi wsgiref wsgiserver