Browse Source

add a python test script

Chia-Che Tsai 6 years ago
parent
commit
bf5022544e
1 changed files with 54 additions and 0 deletions
  1. 54 0
      LibOS/shim/test/apps/python/scripts/dummy-web-server.py

+ 54 - 0
LibOS/shim/test/apps/python/scripts/dummy-web-server.py

@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+"""
+Very simple HTTP server in python.
+Downloaded from: https://gist.github.com/bradmontgomery/2219997
+
+Usage::
+    ./dummy-web-server.py [<port>]
+
+Send a GET request::
+    curl http://localhost
+
+Send a HEAD request::
+    curl -I http://localhost
+
+Send a POST request::
+    curl -d "foo=bar&bin=baz" http://localhost
+
+"""
+
+from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+import SocketServer
+
+class S(BaseHTTPRequestHandler):
+    def _set_headers(self):
+        self.send_response(200)
+        self.send_header('Content-type', 'text/html')
+        self.end_headers()
+
+    def do_GET(self):
+        self._set_headers()
+        self.wfile.write("<html><body><h1>hi!</h1></body></html>")
+
+    def do_HEAD(self):
+        self._set_headers()
+
+    def do_POST(self):
+        # Doesn't do anything with posted data
+        self._set_headers()
+        self.wfile.write("<html><body><h1>POST!</h1></body></html>")
+
+def run(server_class=HTTPServer, handler_class=S, port=80):
+    server_address = ('', port)
+    httpd = server_class(server_address, handler_class)
+    print 'Starting httpd...'
+    httpd.serve_forever()
+
+if __name__ == "__main__":
+    from sys import argv
+
+    if len(argv) == 2:
+        run(port=int(argv[1]))
+    else:
+        run()