Last active
December 17, 2024 06:16
-
-
Save shubham-kaushal/ad9692c504e27201af20aa3347227028 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import argparse | |
import http.server | |
import socketserver | |
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
# Return 200 for all paths | |
self.send_response(200) | |
self.send_header('Content-type', 'text/html; charset=utf-8') # Set UTF-8 encoding | |
self.end_headers() | |
html = """ | |
<html> | |
<head> | |
<title>HTTP Server</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
font-size: 12px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Haiku: Far from the world’s rush, Outpost stands, quiet and still, Sky meets earth in peace.</h1> | |
</body> | |
</html> | |
""" | |
self.wfile.write(bytes(html, 'utf8')) | |
return | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='HTTP Server') | |
parser.add_argument('--port', type=int, required=False, default=8081) | |
args = parser.parse_args() | |
Handler = MyHttpRequestHandler | |
with socketserver.TCPServer(('', args.port), Handler) as httpd: | |
print('serving at port', args.port) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment