diff options
author | Sergey M․ <dstftw@gmail.com> | 2015-08-07 01:26:40 +0600 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2015-08-07 01:26:40 +0600 |
commit | 5a4d9ddb218e761fe7ab15d197690e0cb132a536 (patch) | |
tree | 94ceee7130eae59b1e43419fa6245b4fa887e66b /youtube_dl | |
parent | 671302b5c0ff8cefa5f26e599423ef7799b19631 (diff) |
[utils] Percent-encode redirect URL of Location header (Closes #6457)
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index c7db75f80..e265c7574 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -715,6 +715,17 @@ class YoutubeDLHandler(compat_urllib_request.HTTPHandler): gz = io.BytesIO(self.deflate(resp.read())) resp = self.addinfourl_wrapper(gz, old_resp.headers, old_resp.url, old_resp.code) resp.msg = old_resp.msg + # Percent-encode redirect URL of Location HTTP header to satisfy RFC 3986 + if 300 <= resp.code < 400: + location = resp.headers.get('Location') + if location: + # As of RFC 2616 default charset is iso-8859-1 that is respected by python 3 + if sys.version_info >= (3, 0): + location = location.encode('iso-8859-1').decode('utf-8') + location_escaped = escape_url(location) + if location != location_escaped: + del resp.headers['Location'] + resp.headers['Location'] = location_escaped return resp https_request = http_request |