Exercise 2: Real Content-Type Detection Across Five Extensions — Possible Solution ==================================================================== THE TEST FILES ------------------------------ files = { 'app.js': 'console.log("hi");', 'data.json': '{"a": 1}', 'notes.txt': 'plain text notes', 'style.css': 'body { color: blue; }', 'page.html': '

hi

', } # each written for real to the static directory, then requested # over a real, live CLI-served server VERIFIED, REAL RESULT ------------------------------ app.js: status=200 content-type='text/javascript' match=True data.json: status=200 content-type='application/json' match=True notes.txt: status=200 content-type='text/plain' match=True style.css: status=200 content-type='text/css' match=True page.html: status=200 content-type='text/html' match=True All five real files, served through the exact same serve_static() handler, produced the correct real Content-Type header for their own extension — with zero manual extension-to-MIME-type mapping written anywhere in this framework's own code. WHY THIS WORKS ------------------------------ mimetypes.guess_type() reads from a real, standard, OS-level table of extension-to-MIME-type mappings (the same one most other software on the machine consults) rather than anything this framework maintains itself. Passing it the real resolved file path is enough — it inspects the extension, not the file's actual byte content, so a genuinely correct Content-Type falls out for any of the huge number of extensions Python's own mimetypes module already knows about, with the framework needing only the one guess_type() call and an application/octet-stream fallback for anything it doesn't recognize. WHY THIS WORKS AS AN ANSWER ------------------------------ It verifies real HTTP response headers, not just the return value of mimetypes.guess_type() called directly — confirming the value genuinely makes it all the way from a real file on disk, through safe_static_path() and serve_static(), through Response.to_wsgi(), and into a real, observable HTTP header on a live socket. Testing five genuinely different extensions (rather than just one) confirms the mapping is real and general, not a single lucky match.