zeek/testing/scripts/httpd.py
Robin Sommer 4216a5eb1c Merge remote-tracking branch 'origin/topic/struck/BIT-1277'
* origin/topic/struck/BIT-1277:
  [ADD] Added the feature to return 0 content to the python http test server and added functionality for post requests
  [ADD] added baseline for the new active-http test and added a test to check for the content-length 0 fix.
  [ADD] added baseline for the new exec test and added a test to check for the empty files fix.
  [FIX] exec should write an empty string when file is empty instead of the filename
  [FIX] Add files to result table even if the files are empty

BIT-1277 #merged
2014-10-24 11:43:09 -07:00

55 lines
1.6 KiB
Python
Executable file

#! /usr/bin/env python
import BaseHTTPServer
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
if "/empty" in self.path:
self.wfile.write("")
else:
self.wfile.write("It works!")
def do_POST(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
if "/empty" in self.path:
self.wfile.write("")
else:
self.wfile.write("It works!")
def version_string(self):
return "1.0"
def date_time_string(self):
return "July 22, 2013"
if __name__ == "__main__":
from optparse import OptionParser
p = OptionParser()
p.add_option("-a", "--addr", type="string", default="localhost",
help=("listen on given address (numeric IP or host name), "
"an empty string (the default) means INADDR_ANY"))
p.add_option("-p", "--port", type="int", default=32123,
help="listen on given TCP port number")
p.add_option("-m", "--max", type="int", default=-1,
help="max number of requests to respond to, -1 means no max")
options, args = p.parse_args()
httpd = BaseHTTPServer.HTTPServer((options.addr, options.port),
MyRequestHandler)
if options.max == -1:
httpd.serve_forever()
else:
served_count = 0
while served_count != options.max:
httpd.handle_request()
served_count += 1