diff --git a/test/test_networking.py b/test/test_networking.py index dd8e7d9626..7f7ea5ed10 100644 --- a/test/test_networking.py +++ b/test/test_networking.py @@ -180,6 +180,11 @@ class HTTPTestRequestHandler(http.server.BaseHTTPRequestHandler): self.send_header('Location', '/a/b/./../../headers') self.send_header('Content-Length', '0') self.end_headers() + elif self.path == '/a/b/redirect_relative_dotsegments': + self.send_response(301) + self.send_header('Location', '../../headers') + self.send_header('Content-Length', '0') + self.end_headers() elif self.path == '/redirect_dotsegments_absolute': self.send_response(301) # redirect to /headers but with dot segments before - absolute url @@ -412,6 +417,7 @@ class TestHTTPRequestHandler(TestRequestHandlerBase): @pytest.mark.parametrize('path', [ '/a/b/./../../headers', '/redirect_dotsegments', + '/a/b/redirect_relative_dotsegments', # https://github.com/yt-dlp/yt-dlp/issues/9020 '/redirect_dotsegments_absolute', ]) diff --git a/yt_dlp/networking/_urllib.py b/yt_dlp/networking/_urllib.py index c3f16c99af..d3fe47ccc5 100644 --- a/yt_dlp/networking/_urllib.py +++ b/yt_dlp/networking/_urllib.py @@ -161,17 +161,7 @@ class HTTPHandler(urllib.request.AbstractHTTPHandler): if decoded_response is not None: resp = urllib.request.addinfourl(io.BytesIO(decoded_response), 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 (see - # https://github.com/ytdl-org/youtube-dl/issues/6457). - 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 - location = location.encode('iso-8859-1').decode() - location_escaped = normalize_url(location) - if location != location_escaped: - del resp.headers['Location'] - resp.headers['Location'] = location_escaped + return resp https_request = http_request