mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
minor tweaks: rewrite 'crossorigin' -> '_crossorigin' param to disable
crossorigin as it may interfere with loading rewritten content, add tests for html and lxml parsers add server_cls as optional param to QueryHandler.init_from_config() for easier customization views: dont create template if empty template file specified
This commit is contained in:
parent
23bb5bd175
commit
e1e55ac061
@ -167,6 +167,11 @@ class HTMLRewriterMixin(object):
|
||||
elif attr_name == 'style':
|
||||
attr_value = self._rewrite_css(attr_value)
|
||||
|
||||
# special case: disable crossorigin attr
|
||||
# as they may interfere with rewriting semantics
|
||||
elif attr_name == 'crossorigin':
|
||||
attr_name = '_crossorigin'
|
||||
|
||||
# special case: meta tag
|
||||
elif (tag == 'meta') and (attr_name == 'content'):
|
||||
if self.has_attr(tag_attrs, ('http-equiv', 'refresh')):
|
||||
|
@ -56,6 +56,10 @@ ur"""
|
||||
>>> parse('<script>window.location = "http://example.com/a/b/c.html"</script>')
|
||||
<script>window.WB_wombat_location = "/web/20131226101010em_/http://example.com/a/b/c.html"</script>
|
||||
|
||||
# Script tag + crossorigin
|
||||
>>> parse('<script src="/js/scripts.js" crossorigin="anonymous"></script>')
|
||||
<script src="/web/20131226101010js_/http://example.com/js/scripts.js" _crossorigin="anonymous"></script>
|
||||
|
||||
# Unterminated script tag, handle and auto-terminate
|
||||
>>> parse('<script>window.location = "http://example.com/a/b/c.html"</sc>')
|
||||
<script>window.WB_wombat_location = "/web/20131226101010em_/http://example.com/a/b/c.html"</sc></script>
|
||||
|
@ -51,6 +51,10 @@ ur"""
|
||||
>>> parse('<script>window.location = "http://example.com/a/b/c.html"</script>')
|
||||
<html><head><script>window.WB_wombat_location = "/web/20131226101010em_/http://example.com/a/b/c.html"</script></head></html>
|
||||
|
||||
# Script tag + crossorigin
|
||||
>>> parse('<script src="/js/scripts.js" crossorigin="anonymous"></script>')
|
||||
<html><head><script src="/web/20131226101010js_/http://example.com/js/scripts.js" _crossorigin="anonymous"></script></head></html>
|
||||
|
||||
# Unterminated script tag, will auto-terminate
|
||||
>>> parse('<script>window.location = "http://example.com/a/b/c.html"</sc>')
|
||||
<html><head><script>window.WB_wombat_location = "/web/20131226101010em_/http://example.com/a/b/c.html"</sc></script></head></html>
|
||||
|
@ -33,14 +33,14 @@ class QueryHandler(object):
|
||||
@staticmethod
|
||||
def init_from_config(config,
|
||||
ds_rules_file=DEFAULT_RULES_FILE,
|
||||
html_view=None):
|
||||
html_view=None,
|
||||
server_cls=None):
|
||||
|
||||
perms_policy = None
|
||||
server_cls = None
|
||||
|
||||
if hasattr(config, 'get'):
|
||||
perms_policy = config.get('perms_policy')
|
||||
server_cls = config.get('server_cls')
|
||||
server_cls = config.get('server_cls', server_cls)
|
||||
|
||||
cdx_server = create_cdx_server(config, ds_rules_file, server_cls)
|
||||
|
||||
@ -62,13 +62,6 @@ class QueryHandler(object):
|
||||
# init standard params
|
||||
params = self.get_query_params(wb_url)
|
||||
|
||||
# add any custom filter from the request
|
||||
if wbrequest.query_filter:
|
||||
params['filter'].extend(wbrequest.query_filter)
|
||||
|
||||
if wbrequest.custom_params:
|
||||
params.update(wbrequest.custom_params)
|
||||
|
||||
params['allowFuzzy'] = True
|
||||
params['url'] = wb_url.url
|
||||
params['output'] = output
|
||||
@ -81,6 +74,14 @@ class QueryHandler(object):
|
||||
return self.make_cdx_response(wbrequest, params, cdx_iter)
|
||||
|
||||
def load_cdx(self, wbrequest, params):
|
||||
if wbrequest:
|
||||
# add any custom filter from the request
|
||||
if wbrequest.query_filter:
|
||||
params['filter'].extend(wbrequest.query_filter)
|
||||
|
||||
if wbrequest.custom_params:
|
||||
params.update(wbrequest.custom_params)
|
||||
|
||||
if self.perms_policy:
|
||||
perms_op = make_perms_cdx_filter(self.perms_policy, wbrequest)
|
||||
if perms_op:
|
||||
|
@ -104,6 +104,9 @@ class J2TemplateView:
|
||||
|
||||
@staticmethod
|
||||
def create_template(filename, desc='', view_class=None):
|
||||
if not filename:
|
||||
return None
|
||||
|
||||
if not view_class:
|
||||
view_class = J2TemplateView
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user