mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 08:04:49 +01:00
rangecache: don't redirect when using range header, don't cache non-200
responses
This commit is contained in:
parent
1a91f514c5
commit
9929737a8e
@ -14,7 +14,7 @@ class RangeCache(object):
|
||||
YOUTUBE_RX = re.compile('.*.googlevideo.com/videoplayback')
|
||||
YT_EXTRACT_RX = re.compile('&range=([^&]+)')
|
||||
|
||||
DEFAULT_BUFF = 16384
|
||||
DEFAULT_BUFF = 16384*4
|
||||
|
||||
@staticmethod
|
||||
def match_yt(url):
|
||||
@ -78,9 +78,12 @@ class RangeCache(object):
|
||||
|
||||
key = digest
|
||||
if not key in self.cache:
|
||||
wbrequest.custom_params['noredir'] = True
|
||||
response = wbresponse_func()
|
||||
if not response:
|
||||
return None, None
|
||||
|
||||
# only cache 200 responses
|
||||
if not response.status_headers.get_statuscode().startswith('200'):
|
||||
return response.status_headers, response.body
|
||||
|
||||
with NamedTemporaryFile(delete=False) as fh:
|
||||
for obj in response.body:
|
||||
@ -94,8 +97,6 @@ class RangeCache(object):
|
||||
self.cache[key] = yaml.dump(spec)
|
||||
else:
|
||||
spec = yaml.load(self.cache[key])
|
||||
if not spec:
|
||||
return None, None
|
||||
|
||||
spec['headers'] = [tuple(x) for x in spec['headers']]
|
||||
|
||||
|
@ -201,7 +201,11 @@ class ReplayView(object):
|
||||
if wbrequest.options['is_proxy']:
|
||||
return None
|
||||
|
||||
if range_cache and range_cache.match_yt(wbrequest.wb_url.url):
|
||||
if range_cache:
|
||||
if range_cache.match_yt(wbrequest.wb_url.url) or wbrequest.env.get('HTTP_RANGE'):
|
||||
return None
|
||||
|
||||
if wbrequest.custom_params.get('noredir'):
|
||||
return None
|
||||
|
||||
redir_needed = (wbrequest.options.get('is_timegate', False))
|
||||
|
Loading…
x
Reference in New Issue
Block a user