##// END OF EJS Templates
dumbhttp: use IPv6 if HGIPV6 is set to 1...
Jun Wu -
r31004:d05fefbb default
parent child Browse files
Show More
@@ -1,55 +1,63 b''
1 1 #!/usr/bin/env python
2 2
3 3 from __future__ import absolute_import
4 4
5 5 """
6 6 Small and dumb HTTP server for use in tests.
7 7 """
8 8
9 9 import optparse
10 import os
10 11 import signal
12 import socket
11 13 import sys
12 14
13 15 from mercurial import (
14 16 server,
15 17 util,
16 18 )
17 19
18 20 httpserver = util.httpserver
19 21 OptionParser = optparse.OptionParser
20 22
23 if os.environ.get('HGIPV6', '0') == '1':
24 class simplehttpserver(httpserver.httpserver):
25 address_family = socket.AF_INET6
26 else:
27 simplehttpserver = httpserver.httpserver
28
21 29 class simplehttpservice(object):
22 30 def __init__(self, host, port):
23 31 self.address = (host, port)
24 32 def init(self):
25 self.httpd = httpserver.httpserver(
33 self.httpd = simplehttpserver(
26 34 self.address, httpserver.simplehttprequesthandler)
27 35 def run(self):
28 36 self.httpd.serve_forever()
29 37
30 38 if __name__ == '__main__':
31 39 parser = OptionParser()
32 40 parser.add_option('-p', '--port', dest='port', type='int', default=8000,
33 41 help='TCP port to listen on', metavar='PORT')
34 42 parser.add_option('-H', '--host', dest='host', default='localhost',
35 43 help='hostname or IP to listen on', metavar='HOST')
36 44 parser.add_option('--pid', dest='pid',
37 45 help='file name where the PID of the server is stored')
38 46 parser.add_option('-f', '--foreground', dest='foreground',
39 47 action='store_true',
40 48 help='do not start the HTTP server in the background')
41 49 parser.add_option('--daemon-postexec', action='append')
42 50
43 51 (options, args) = parser.parse_args()
44 52
45 53 signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0))
46 54
47 55 if options.foreground and options.pid:
48 56 parser.error("options --pid and --foreground are mutually exclusive")
49 57
50 58 opts = {'pid_file': options.pid,
51 59 'daemon': not options.foreground,
52 60 'daemon_postexec': options.daemon_postexec}
53 61 service = simplehttpservice(options.host, options.port)
54 62 server.runservice(opts, initfn=service.init, runfn=service.run,
55 63 runargs=[sys.executable, __file__] + sys.argv[1:])
General Comments 0
You need to be logged in to leave comments. Login now