#!/usr/bin/env python """ Very simple HTTP server in python (Updated for Python 3.7) Usage: ./dummy-web-server.py -h ./dummy-web-server.py -l localhost -p 8000 Send a GET request: curl http://localhost:8000 Send a HEAD request: curl -I http://localhost:8000 Send a POST request: curl -d "foo=bar&bin=baz" http://localhost:8000 This code is available for use under the MIT license. ---- Copyright 2021 Brad Montgomery Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import argparse from http.server import HTTPServer, BaseHTTPRequestHandler class S(BaseHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() def _html(self, message): """This just generates an HTML document that includes `message` in the body. Override, or re-write this do do more interesting stuff. """ content = f"