Compare commits

...

11 Commits

Author SHA1 Message Date
bashonly a1d327f455
Merge 6c7bfb5c7c into 1a366403d9 2024-04-28 19:37:08 +02:00
bashonly 1a366403d9
[build] Run `macos_legacy` job on `macos-12` (#9804)
`macos-latest` has been bumped to `macos-14-arm64` which breaks the builds

Authored by: bashonly
2024-04-28 15:35:17 +00:00
Simon Sawicki 7e26bd53f9
[core/windows] Fix tests for `sys.executable` with spaces (Fix for 64766459e3)
Authored by: Grub4K
2024-04-28 15:47:55 +02:00
bashonly 6c7bfb5c7c
oops
Authored by: bashonly
2024-04-23 18:28:43 -05:00
bashonly 805f40a001
add tests
Authored by: bashonly
2024-04-23 18:22:58 -05:00
bashonly b77ccbc67b
new impl
Authored by: bashonly
2024-04-23 18:04:12 -05:00
bashonly d5d83395ab
revert to orig impl
Authored by: bashonly
2024-04-23 14:33:48 -05:00
bashonly f2f108b754
fix test
Authored by: bashonly
2024-04-22 23:56:28 -05:00
bashonly d66fa6a118
Merge branch 'yt-dlp:master' into feat/impersonate-response 2024-04-22 17:46:43 -05:00
bashonly 3b48105b8c
slight impl change
Authored by: bashonly
2024-04-22 17:41:20 -05:00
bashonly 64d4c4ba72
[networking] Add `ImpersonateResponse`
Authored by: bashonly
2024-04-21 13:00:31 -05:00
5 changed files with 31 additions and 5 deletions

View File

@ -300,7 +300,7 @@ jobs:
macos_legacy:
needs: process
if: inputs.macos_legacy
runs-on: macos-latest
runs-on: macos-12
steps:
- uses: actions/checkout@v4

View File

@ -785,6 +785,25 @@ class TestHTTPImpersonateRequestHandler(TestRequestHandlerBase):
assert res.status == 200
assert std_headers['user-agent'].lower() not in res.read().decode().lower()
def test_response_extensions(self, handler):
with handler() as rh:
for target in rh.supported_targets:
request = Request(
f'http://127.0.0.1:{self.http_port}/gen_200', extensions={'impersonate': target})
res = validate_and_send(rh, request)
assert res.extensions['impersonate'] == rh._get_request_target(request)
def test_http_error_response_extensions(self, handler):
with handler() as rh:
for target in rh.supported_targets:
request = Request(
f'http://127.0.0.1:{self.http_port}/gen_404', extensions={'impersonate': target})
try:
validate_and_send(rh, request)
except HTTPError as e:
res = e.response
assert res.extensions['impersonate'] == rh._get_request_target(request)
class TestRequestHandlerMisc:
"""Misc generic tests for request handlers, not related to request or validation testing"""

View File

@ -2090,10 +2090,7 @@ Line 1
args = [sys.executable, '-c', 'import sys; print(end=sys.argv[1])', argument, 'end']
assert run_shell(args) == expected
escaped = shell_quote(argument, shell=True)
args = f'{sys.executable} -c "import sys; print(end=sys.argv[1])" {escaped} end'
assert run_shell(args) == expected
assert run_shell(shell_quote(args, shell=True)) == expected
if __name__ == '__main__':

View File

@ -132,6 +132,15 @@ class CurlCFFIRH(ImpersonateRequestHandler, InstanceStoreMixin):
extensions.pop('cookiejar', None)
extensions.pop('timeout', None)
def send(self, request: Request) -> Response:
try:
response = super().send(request)
except HTTPError as e:
e.response.extensions['impersonate'] = self._get_request_target(request)
raise
response.extensions['impersonate'] = self._get_request_target(request)
return response
def _send(self, request: Request):
max_redirects_exceeded = False
session: curl_cffi.requests.Session = self._get_instance(

View File

@ -517,6 +517,7 @@ class Response(io.IOBase):
self.reason = reason or HTTPStatus(status).phrase
except ValueError:
self.reason = None
self.extensions = {}
def readable(self):
return self.fp.readable()