-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserve.py
executable file
·64 lines (56 loc) · 2.7 KB
/
serve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#===============================================================================#
# #
# rmem executable model #
# ===================== #
# #
# This file is: #
# #
# Copyright Jon French, University of Cambridge 2017 #
# Copyright Shaked Flur, University of Cambridge 2017 #
# #
# All rights reserved. #
# #
# It is part of the rmem tool, distributed under the 2-clause BSD licence in #
# LICENCE.txt. #
# #
#===============================================================================#
#!/usr/bin/env python
from __future__ import print_function
import argparse
import sys
PY3 = (sys.version_info > (3, 0))
if PY3:
import http.server
import socketserver
base = http.server.SimpleHTTPRequestHandler
server_module = http.server
socket_module = socketserver
else:
import BaseHTTPServer
import SimpleHTTPServer
import SocketServer
base = SimpleHTTPServer.SimpleHTTPRequestHandler
server_module = BaseHTTPServer
socket_module = SocketServer
class RequestHandler(base, object):
protocol_version = "HTTP/1.1"
def end_headers(self):
self.send_header("Cache-Control", "max-age=0, no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "Thu, 01 Jan 1970 00:00:00 UTC")
super(RequestHandler, self).end_headers()
class HTTPServer(socket_module.ThreadingMixIn, server_module.HTTPServer):
pass
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("port", action="store", default=8000, type=int, nargs="?")
args = parser.parse_args()
httpd = HTTPServer(("localhost", args.port), RequestHandler)
sa = httpd.socket.getsockname()
print("Serving HTTP on", sa[0], "port", sa[1], "...")
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
httpd.server_close()
sys.exit(0)