Last active
September 10, 2023 19:29
-
-
Save yeukhon/7272851 to your computer and use it in GitHub Desktop.
server.py
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
# 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