mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 07:04:38 +00:00
[networking] Fix POST requests with zero-length payloads (#7648)
Bugfix for 227bf1a33b
Authored by: bashonly
This commit is contained in:
parent
613dbce177
commit
71baa490eb
4 changed files with 14 additions and 3 deletions
|
@ -1280,6 +1280,17 @@ class TestRequest:
|
||||||
req.data = b'test3'
|
req.data = b'test3'
|
||||||
assert req.headers.get('Content-Type') == 'application/x-www-form-urlencoded'
|
assert req.headers.get('Content-Type') == 'application/x-www-form-urlencoded'
|
||||||
|
|
||||||
|
def test_update_req(self):
|
||||||
|
req = Request('http://example.com')
|
||||||
|
assert req.data is None
|
||||||
|
assert req.method == 'GET'
|
||||||
|
assert 'Content-Type' not in req.headers
|
||||||
|
# Test that zero-byte payloads will be sent
|
||||||
|
req.update(data=b'')
|
||||||
|
assert req.data == b''
|
||||||
|
assert req.method == 'POST'
|
||||||
|
assert req.headers.get('Content-Type') == 'application/x-www-form-urlencoded'
|
||||||
|
|
||||||
def test_proxies(self):
|
def test_proxies(self):
|
||||||
req = Request(url='http://example.com', proxies={'http': 'http://127.0.0.1:8080'})
|
req = Request(url='http://example.com', proxies={'http': 'http://127.0.0.1:8080'})
|
||||||
assert req.proxies == {'http': 'http://127.0.0.1:8080'}
|
assert req.proxies == {'http': 'http://127.0.0.1:8080'}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class EttuTvIE(InfoExtractor):
|
||||||
'device': 'desktop',
|
'device': 'desktop',
|
||||||
})
|
})
|
||||||
|
|
||||||
stream_response = self._download_json(player_settings['streamAccess'], video_id, data={})
|
stream_response = self._download_json(player_settings['streamAccess'], video_id, data=b'')
|
||||||
|
|
||||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
||||||
stream_response['data']['stream'], video_id, 'mp4')
|
stream_response['data']['stream'], video_id, 'mp4')
|
||||||
|
|
|
@ -315,7 +315,7 @@ class HEADRequest(urllib.request.Request):
|
||||||
def update_Request(req, url=None, data=None, headers=None, query=None):
|
def update_Request(req, url=None, data=None, headers=None, query=None):
|
||||||
req_headers = req.headers.copy()
|
req_headers = req.headers.copy()
|
||||||
req_headers.update(headers or {})
|
req_headers.update(headers or {})
|
||||||
req_data = data or req.data
|
req_data = data if data is not None else req.data
|
||||||
req_url = update_url_query(url or req.get_full_url(), query)
|
req_url = update_url_query(url or req.get_full_url(), query)
|
||||||
req_get_method = req.get_method()
|
req_get_method = req.get_method()
|
||||||
if req_get_method == 'HEAD':
|
if req_get_method == 'HEAD':
|
||||||
|
|
|
@ -425,7 +425,7 @@ class Request:
|
||||||
raise TypeError('headers must be a mapping')
|
raise TypeError('headers must be a mapping')
|
||||||
|
|
||||||
def update(self, url=None, data=None, headers=None, query=None):
|
def update(self, url=None, data=None, headers=None, query=None):
|
||||||
self.data = data or self.data
|
self.data = data if data is not None else self.data
|
||||||
self.headers.update(headers or {})
|
self.headers.update(headers or {})
|
||||||
self.url = update_url_query(url or self.url, query or {})
|
self.url = update_url_query(url or self.url, query or {})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue