Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test-server no cache header added (i think)

  • Loading branch information...
commit e0a6f56a5918cc352b83919c2beeac09ea4af2a7 1 parent 4a23d51
@secretrobotron secretrobotron authored
Showing with 8 additions and 53 deletions.
  1. +8 −53 tools/test-server.py
View
61 tools/test-server.py
@@ -13,69 +13,30 @@
SLOW = False
MAX_SLOW_TIME = .10
-g_stop_server = False
-
-def createSlowHandler(ParentClass):
+def createHandler(ParentClass):
class SlowHandler(ParentClass):
def __init__(self, request, client_address, server):
- return ParentClass.__init__(self, request, client_address, server)
+ ParentClass.__init__(self, request, client_address, server)
def do_HEAD(self):
- global g_stop_server
- try:
- time.sleep(random.random() * MAX_SLOW_TIME)
- except KeyboardInterrupt:
- g_stop_server = True
return ParentClass.do_HEAD(self)
def do_GET(self):
- global g_stop_server
- try:
- time.sleep(random.random() * MAX_SLOW_TIME)
- except KeyboardInterrupt:
- g_stop_server = True
+ self.headers.headers.append("Cache-Control: no-cache")
return ParentClass.do_GET(self)
return SlowHandler
-def createStoppableServer(ParentClass):
- class StoppableServer(ParentClass):
-
- stopped = False
-
- def __init__(self, *args, **kw):
- ParentClass.__init__(self, *args, **kw)
-
- def serve_forever(self):
- while not self.stopped:
- self.handle_request()
- if g_stop_server:
- self.force_stop()
-
- def force_stop(self):
- self.server_close()
- self.stopped = True
-
- return StoppableServer
-
if "--port" in sys.argv:
PORT = int(sys.argv[sys.argv.index("--port") + 1])
-if "--slow" in sys.argv:
- SLOW = True
-
try:
try:
import SimpleHTTPServer
import SocketServer
- if SLOW:
- print "Warning: --slow argument specified. Requests will be stunted."
- Handler = createSlowHandler(SimpleHTTPServer.SimpleHTTPRequestHandler)
- else:
- Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
-
- Server = createStoppableServer(SocketServer.TCPServer)
+ Handler = createHandler(SimpleHTTPServer.SimpleHTTPRequestHandler)
+ Server = SocketServer.TCPServer
httpd = Server(("localhost", PORT), Handler)
print "Web Server listening on http://localhost:%s/ (stop with ctrl+c)..." % PORT
@@ -84,18 +45,12 @@ def force_stop(self):
except ImportError:
from http.server import HTTPServer, SimpleHTTPRequestHandler
- if SLOW:
- print "Warning: --slow argument specified. Requests will be stunted."
- Handler = createSlowHandler(SimpleHTTPRequestHandler)
- else:
- Handler = SimpleHTTPRequestHandler
-
- Server = createStoppableServer(HTTPServer)
+ Handler = createHandler(SimpleHTTPRequestHandler)
+ Server = HTTPServer
httpd = Server(('localhost', PORT), Handler)
print "Web Server listening on http://localhost:%s/ (stop with ctrl+c)..." % PORT
httpd.serve_forever()
except BaseException, e:
- print(e)
- g_stop_server = True
+ print(e)
Please sign in to comment.
Something went wrong with that request. Please try again.