1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 08:04:49 +01:00
pywb/tests_disabled/server_thread.py
Ilya Kreymer a4b770d34e new-pywb refactor!
frontendapp compatibility
- add support for separate not found page for 404s (not_found.html)
- support for exception handling with error template (error.html)
- support for home page (index.html)
- add memento headers for replay
- add referrer fallback check
- tests: port integration tests for front-end replay, cdx server
- not included: proxy mode, exact redirect mode, non-framed replay
- move unused tests to tests_disabled
- cli: add optional werkzeug profiler with --profile flag
2017-02-27 19:07:51 -08:00

38 lines
1.0 KiB
Python

import threading
from pywb.webapp.pywb_init import create_wb_router
from pywb.framework.wsgi_wrappers import init_app
# disable is_hop_by_hop restrictions
import wsgiref.handlers
wsgiref.handlers.is_hop_by_hop = lambda x: False
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_str = proxy_str
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()