1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00
pywb/tests/server_thread.py
Ilya Kreymer a9892f531f proxy testing: refactored test server thread into ServerThreadRunner
class which runs a server in a seperate thread.. used by http/s proxies
as well, as mock live server proxy
add test for live rewrite with proxy, covering simple case as well as
video
2014-12-23 11:07:47 -08:00

33 lines
911 B
Python

import threading
from pywb.webapp.pywb_init import create_wb_router
from pywb.framework.wsgi_wrappers import init_app
class ServerThreadRunner(object):
def __init__(self, make_httpd, config_file=None):
if config_file:
self.app = init_app(create_wb_router,
load_yaml=True,
config_file=config_file)
else:
self.app = None
self.httpd = make_httpd(self.app)
self.port = self.httpd.socket.getsockname()[1]
proxy_str = 'http://localhost:' + str(self.port)
self.proxy_dict = {'http': proxy_str,
'https': proxy_str}
def run():
self.httpd.serve_forever()
self.thread = threading.Thread(target=run)
self.thread.daemon = True
self.thread.start()
def stop_thread(self):
self.httpd.shutdown()