1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-28 00:25:21 +01:00
pywb/pywb/webapp/live_rewrite_handler.py
Ilya Kreymer 6da27789eb live handler: allow live rewrite handler to be specified as one of the collections in pywb
by settings index_paths to '$liveweb'. When used, creates a RewriteHandler instead of WBHandler
Can also specify 'proxyhostport' to set the live rewrite to go through a proxy

fallback: allow fallback to a different handler (usually live rewrite) by specifying
'redir_fallback' with name of handler. Instead of 404, a not found response will
internally call the fallback handler to get a response
2014-07-20 16:42:00 -07:00

29 lines
908 B
Python

from pywb.framework.basehandlers import WbUrlHandler
from pywb.framework.wbrequestresponse import WbResponse
from pywb.framework.archivalrouter import ArchivalRouter, Route
from handlers import StaticHandler
from replay_views import RewriteLiveView
#=================================================================
class RewriteHandler(WbUrlHandler):
def __init__(self, config):
self.rewrite_view = RewriteLiveView(config)
def __call__(self, wbrequest):
return self.rewrite_view(wbrequest)
def __str__(self):
return 'Live Web Rewrite Handler'
#=================================================================
def create_live_rewriter_app(config={}):
routes = [Route('rewrite', RewriteHandler(config)),
Route('static/default', StaticHandler('pywb/static/'))
]
return ArchivalRouter(routes, hostpaths=['http://localhost:8080'])