Created
April 28, 2020 22:15
-
-
Save cobookman/77d91b59696f45e1f2fc5ee37a908936 to your computer and use it in GitHub Desktop.
Dummy HTTP Server for python2.7
This file contains 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 time | |
import BaseHTTPServer | |
HOST_NAME = '0.0.0.0' | |
PORT_NUMBER = 80 | |
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
def do_HEAD(s): | |
s.send_response(200) | |
s.send_header("Content-type", "text/html") | |
s.end_headers() | |
def do_GET(s): | |
"""Respond to a GET request.""" | |
s.send_response(200) | |
s.send_header("Content-type", "text/html") | |
s.end_headers() | |
s.wfile.write("<html><head><title>Title goes here.</title></head>") | |
s.wfile.write("<body><p>This is a test.</p>") | |
s.wfile.write("<p>Your IP address is: %s</p>" % s.address_string()) | |
# If someone went to "http://something.somewhere.net/foo/bar/", | |
# then s.path equals "/foo/bar/". | |
s.wfile.write("<p>You accessed path: %s</p>" % s.path) | |
s.wfile.write("</body></html>") | |
if __name__ == '__main__': | |
server_class = BaseHTTPServer.HTTPServer | |
httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler) | |
print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER) | |
try: | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
pass | |
httpd.server_close() | |
print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lab Instructions:
https://docs.google.com/document/d/1Kw4dhhjFLvRXUMZzr9HsIDt8mQfccXopP9jbPdd5NX8/edit?usp=sharing