blob: 1d994a60d65fe489b2f79b46b65233737505de0c [file] [log] [blame]
Masayuki Igawa46c688c2014-02-24 18:42:37 +09001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
Jesse Andrews64164072011-11-05 22:15:50 -070012
Masayuki Igawa46c688c2014-02-24 18:42:37 +090013import BaseHTTPServer
14import SimpleHTTPServer
15import sys
16
17
18def main(host, port, HandlerClass=SimpleHTTPServer.SimpleHTTPRequestHandler,
19 ServerClass=BaseHTTPServer.HTTPServer, protocol="HTTP/1.0"):
20 """simple http server that listens on a give address:port."""
Jesse Andrews64164072011-11-05 22:15:50 -070021
22 server_address = (host, port)
23
24 HandlerClass.protocol_version = protocol
25 httpd = ServerClass(server_address, HandlerClass)
26
27 sa = httpd.socket.getsockname()
Masayuki Igawa46c688c2014-02-24 18:42:37 +090028 print("Serving HTTP on", sa[0], "port", sa[1], "...")
Jesse Andrews64164072011-11-05 22:15:50 -070029 httpd.serve_forever()
30
31if __name__ == '__main__':
32 if sys.argv[1:]:
33 address = sys.argv[1]
34 else:
35 address = '0.0.0.0'
36 if ':' in address:
37 host, port = address.split(':')
38 else:
39 host = address
40 port = 8080
41
42 main(host, int(port))