wget "https://tiddlywiki.com/empty.html"
./app
- open http://localhost:8080
-
-
Save FND/76cf34ddca1e258aa502d70ec98d551d to your computer and use it in GitHub Desktop.
WSGI streaming from disk (test case)
This file contains 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
#!/usr/bin/env python3 | |
import os | |
ROOT_DIR = os.path.dirname(__file__) | |
FILENAME = "empty.html" | |
def handler(environ, start_response): | |
method = environ["REQUEST_METHOD"] | |
if method != "GET": | |
start_response("405 Method Not Allowed", []) | |
return [] | |
start_response("200 OK", [("Content-Type", "text/html")]) | |
filepath = os.path.abspath(os.path.join(ROOT_DIR, FILENAME)) | |
fh = open(filepath) | |
return (chunk.encode("utf-8") for chunk in fh) | |
if __name__ == "__main__": | |
from wsgiref.simple_server import make_server | |
host = "localhost" | |
port = 8080 | |
srv = make_server(host, port, handler) | |
print("→ http://%s:%s" % (host, port)) | |
srv.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment