-
Notifications
You must be signed in to change notification settings - Fork 13
/
run-testing-server.py
executable file
·84 lines (61 loc) · 2.84 KB
/
run-testing-server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import ssl
from threading import Thread, Lock
import time
import SimpleHTTPServer
import BaseHTTPServer
from request_handlers import GzipSimpleHTTPServer, SimpleAuthHandler
log_mutex = Lock()
def log(message):
log_mutex.acquire()
try:
print message
finally:
log_mutex.release()
def start_http_server(port):
log("(%d) Starting HTTP Server..." % port)
httpd = BaseHTTPServer.HTTPServer(("", port), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.serve_forever()
def start_https_server(port, certificate):
log("(%d) Starting HTTPS Server..." % port)
httpd = BaseHTTPServer.HTTPServer(("", port), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile=certificate, server_side=True)
httpd.serve_forever()
def start_gziped_http_server(port):
log("(%d) Starting Gziped HTTP Server..." % port)
httpd = BaseHTTPServer.HTTPServer(("", port), GzipSimpleHTTPServer)
httpd.serve_forever()
def start_gziped_https_server(port, certificate):
log("(%d) Starting Gziped HTTPS Server..." % port)
httpd = BaseHTTPServer.HTTPServer(("", port), GzipSimpleHTTPServer)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile=certificate, server_side=True)
httpd.serve_forever()
def start_http_server_with_basic_auth(port):
log("(%d) Starting HTTP Server with Basic Auth..." % port)
httpd = BaseHTTPServer.HTTPServer(("", port), SimpleAuthHandler)
httpd.serve_forever()
def start_https_server_with_basic_auth(port, certificate):
log("(%d) Starting HTTPS Server with Basic Auth..." % port)
httpd = BaseHTTPServer.HTTPServer(("", port), SimpleAuthHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile=certificate, server_side=True)
httpd.serve_forever()
if __name__ == "__main__":
script_location = os.path.dirname(os.path.abspath(__file__))
site_location = os.path.join(script_location, "test-data", "site")
certfile = os.path.join(script_location, "test-data", "certificates", "self-ssl.pem")
os.chdir(site_location)
print "Serving", os.getcwd(), "directory"
server_threads = [Thread(target = start_http_server, args = (8001,)),
Thread(target = start_https_server, args = (4443, certfile)),
Thread(target = start_gziped_http_server, args = (8002,)),
Thread(target = start_gziped_https_server, args = (4444, certfile)),
Thread(target = start_http_server_with_basic_auth, args = (8003,)),
Thread(target = start_https_server_with_basic_auth, args = (4445, certfile))]
for thread in server_threads:
thread.daemon = True
thread.start()
# This loop allows you to ^C when you run this script standalone
while True:
time.sleep(1)