Skip to content

Instantly share code, notes, and snippets.

@yeukhon
Last active September 10, 2023 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeukhon/7272851 to your computer and use it in GitHub Desktop.
Save yeukhon/7272851 to your computer and use it in GitHub Desktop.
server.py
# adopt this from https://wiki.python.org/moin/BaseHttpServer
# life would be easier if Bottle was included in stdlib.
import BaseHTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 9999
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(s):
"""Respond to a GET request."""
s.send_response(200)
s.send_header('content-security-policy', "DEFAULT-SRC 'self'")
s.end_headers()
s.wfile.write("""\
<html><head></head><body>
<img src="http://www.w3schools.com/images/w3logotest2.png" alt="logo" height="42" width="42">
</body>
</html>""")
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment