mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 06:35:12 +00:00 
			
		
		
		
	[rh:requests] Work around partial read dropping data (#13599)
Authored by: Grub4K
This commit is contained in:
		| @@ -22,7 +22,6 @@ import ssl | ||||
| import tempfile | ||||
| import threading | ||||
| import time | ||||
| import urllib.error | ||||
| import urllib.request | ||||
| import warnings | ||||
| import zlib | ||||
| @@ -223,10 +222,7 @@ class HTTPTestRequestHandler(http.server.BaseHTTPRequestHandler): | ||||
|                 if encoding == 'br' and brotli: | ||||
|                     payload = brotli.compress(payload) | ||||
|                 elif encoding == 'gzip': | ||||
|                     buf = io.BytesIO() | ||||
|                     with gzip.GzipFile(fileobj=buf, mode='wb') as f: | ||||
|                         f.write(payload) | ||||
|                     payload = buf.getvalue() | ||||
|                     payload = gzip.compress(payload, mtime=0) | ||||
|                 elif encoding == 'deflate': | ||||
|                     payload = zlib.compress(payload) | ||||
|                 elif encoding == 'unsupported': | ||||
| @@ -729,6 +725,17 @@ class TestHTTPRequestHandler(TestRequestHandlerBase): | ||||
| 
 | ||||
|             assert 'X-test-heaDer: test' in res | ||||
| 
 | ||||
|     def test_partial_read_then_full_read(self, handler): | ||||
|         with handler() as rh: | ||||
|             for encoding in ('', 'gzip', 'deflate'): | ||||
|                 res = validate_and_send(rh, Request( | ||||
|                     f'http://127.0.0.1:{self.http_port}/content-encoding', | ||||
|                     headers={'ytdl-encoding': encoding})) | ||||
|                 assert res.headers.get('Content-Encoding') == encoding | ||||
|                 assert res.read(6) == b'<html>' | ||||
|                 assert res.read(0) == b'' | ||||
|                 assert res.read() == b'<video src="/vid.mp4" /></html>' | ||||
| 
 | ||||
| 
 | ||||
| @pytest.mark.parametrize('handler', ['Urllib', 'Requests', 'CurlCFFI'], indirect=True) | ||||
| class TestClientCertificate: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Simon Sawicki
					Simon Sawicki