Skip to content

Instantly share code, notes, and snippets.

@yoya
Last active July 6, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoya/76ca7ee545d5c506ea2d90232d0af820 to your computer and use it in GitHub Desktop.
Save yoya/76ca7ee545d5c506ea2d90232d0af820 to your computer and use it in GitHub Desktop.
python http server
#! /usr/local/bin/python3
# https://docs.python.jp/3/library/http.server.html
# https://blog.sarabande.jp/post/81479479934
from http.server import HTTPServer, SimpleHTTPRequestHandler
[host, port] = ["0.0.0.0", 4848]
class MyHandler(SimpleHTTPRequestHandler):
def do_GET(self):
body = b'Hello World'
self.send_response(200)
self.send_header('Content-type', 'text/html; charset=utf-8')
# self.send_header('Content-length', len(body))
self.end_headers()
self.wfile.write(body)
httpd = HTTPServer((host, port), MyHandler)
print('serving at port', port)
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment