mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-27 10:56:48 +01:00
[extractor/common] Move X-Forwarded-For setup code into _request_webpage
This commit is contained in:
parent
4b7dd1705a
commit
2132edaa03
@ -495,6 +495,16 @@ class InfoExtractor(object):
|
|||||||
self.to_screen('%s' % (note,))
|
self.to_screen('%s' % (note,))
|
||||||
else:
|
else:
|
||||||
self.to_screen('%s: %s' % (video_id, note))
|
self.to_screen('%s: %s' % (video_id, note))
|
||||||
|
|
||||||
|
# Some sites check X-Forwarded-For HTTP header in order to figure out
|
||||||
|
# the origin of the client behind proxy. This allows bypassing geo
|
||||||
|
# restriction by faking this header's value to IP that belongs to some
|
||||||
|
# geo unrestricted country. We will do so once we encounter any
|
||||||
|
# geo restriction error.
|
||||||
|
if self._x_forwarded_for_ip:
|
||||||
|
if 'X-Forwarded-For' not in headers:
|
||||||
|
headers['X-Forwarded-For'] = self._x_forwarded_for_ip
|
||||||
|
|
||||||
if isinstance(url_or_request, compat_urllib_request.Request):
|
if isinstance(url_or_request, compat_urllib_request.Request):
|
||||||
url_or_request = update_Request(
|
url_or_request = update_Request(
|
||||||
url_or_request, data=data, headers=headers, query=query)
|
url_or_request, data=data, headers=headers, query=query)
|
||||||
@ -524,15 +534,6 @@ class InfoExtractor(object):
|
|||||||
if isinstance(url_or_request, (compat_str, str)):
|
if isinstance(url_or_request, (compat_str, str)):
|
||||||
url_or_request = url_or_request.partition('#')[0]
|
url_or_request = url_or_request.partition('#')[0]
|
||||||
|
|
||||||
# Some sites check X-Forwarded-For HTTP header in order to figure out
|
|
||||||
# the origin of the client behind proxy. This allows bypassing geo
|
|
||||||
# restriction by faking this header's value to IP that belongs to some
|
|
||||||
# geo unrestricted country. We will do so once we encounter any
|
|
||||||
# geo restriction error.
|
|
||||||
if self._x_forwarded_for_ip:
|
|
||||||
if 'X-Forwarded-For' not in headers:
|
|
||||||
headers['X-Forwarded-For'] = self._x_forwarded_for_ip
|
|
||||||
|
|
||||||
urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query)
|
urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query)
|
||||||
if urlh is False:
|
if urlh is False:
|
||||||
assert not fatal
|
assert not fatal
|
||||||
|
Loading…
Reference in New Issue
Block a user