about summary refs log tree commit diff
path: root/test
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2023-07-24 03:30:28 +0100
committerdirkf <fieldhouse@gmx.net>2023-07-25 13:19:43 +0100
commit2b7dd3b2a2d7c6e228a42d1000a6f3296739ff1c (patch)
tree83905f983970d110059630cf9b9f808d4c1a4f84 /test
parent44faa71b19c866b836e4433ddd3e4722ac6d282f (diff)
downloadyoutube-dl-2b7dd3b2a2d7c6e228a42d1000a6f3296739ff1c.tar.gz
youtube-dl-2b7dd3b2a2d7c6e228a42d1000a6f3296739ff1c.tar.xz
youtube-dl-2b7dd3b2a2d7c6e228a42d1000a6f3296739ff1c.zip
[utils] Fix update_Request() with empty data (not None)
Diffstat (limited to 'test')
-rw-r--r--test/test_http.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/test_http.py b/test/test_http.py
index 4ec8e13e3..89580969d 100644
--- a/test/test_http.py
+++ b/test/test_http.py
@@ -41,6 +41,7 @@ from youtube_dl.compat import (
 
 from youtube_dl.utils import (
     sanitized_Request,
+    update_Request,
     urlencode_postdata,
 )
 
@@ -395,6 +396,18 @@ class TestHTTP(unittest.TestCase):
             headers = ydl.urlopen(r).read().decode('utf-8')
             self.assertIn('Content-Type: application/x-www-form-urlencoded', headers)
 
+    def test_update_req(self):
+        req = sanitized_Request('http://example.com')
+        assert req.data is None
+        assert req.get_method() == 'GET'
+        assert not req.has_header('Content-Type')
+        # Test that zero-byte payloads will be sent
+        req = update_Request(req, data=b'')
+        assert req.data == b''
+        assert req.get_method() == 'POST'
+        # yt-dl expects data to be encoded and Content-Type to be added by sender
+        # assert req.get_header('Content-Type') == 'application/x-www-form-urlencoded'
+
     def test_cookiejar(self):
         with FakeYDL() as ydl:
             ydl.cookiejar.set_cookie(compat_http_cookiejar_Cookie(