mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-23 22:52:25 +01:00
- rewrite headers after content to ensure content-length/content-encoding rewritten if content modified - header rewriter: remove proxyrewriter, set default rule to 'prefix' or 'keep' if url rewriting or not - set is_content_rw if record.content_stream(), assume content is modified - add BufferedRewriter as base for dash, hls, amf rewriting which processes the full stream - should_rw_content() determines if should attempt content rewriting - support banner-only insert mode: added HTMLInsertOnlyRewriter, enable if no custom JS rules - test: enable banner-only test mode
29 lines
773 B
Python
29 lines
773 B
Python
import re
|
|
from pywb.rewrite.content_rewriter import StreamingRewriter
|
|
|
|
|
|
# ============================================================================
|
|
class JSONPRewriter(StreamingRewriter):
|
|
JSONP = re.compile(r'^(\w+)\(\{')
|
|
CALLBACK = re.compile(r'[?].*callback=([^&]+)')
|
|
|
|
def rewrite(self, string):
|
|
# see if json is jsonp, starts with callback func
|
|
m_json = self.JSONP.search(string)
|
|
if not m_json:
|
|
return string
|
|
|
|
# see if there is a callback param in current url
|
|
m_callback = self.CALLBACK.search(self.urlrewriter.wburl.url)
|
|
if not m_callback:
|
|
return string
|
|
|
|
string = m_callback.group(1) + string[m_json.end(1):]
|
|
return string
|
|
|
|
def close(self):
|
|
return ''
|
|
|
|
|
|
|