aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2016-03-31 22:55:01 +0600
committerSergey M․ <dstftw@gmail.com>2016-03-31 22:55:01 +0600
commited0291d1533600b21903cb98f070791a20e47433 (patch)
treed404146ca50191ab3e048208d1ce53fcca0dc3ef
parent81da8cbc4513df16d0d04dc2992d6de9ab0f4038 (diff)
[utils] Add update_Request
-rw-r--r--youtube_dl/utils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 6d27b80c0..4532b737b 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1804,6 +1804,20 @@ def update_url_query(url, query):
query=compat_urllib_parse_urlencode(qs, True)))
+def update_Request(req, url=None, data=None, headers={}, query={}):
+ req_headers = req.headers.copy()
+ req_headers.update(headers)
+ req_data = data or req.data
+ req_url = update_url_query(url or req.get_full_url(), query)
+ req_type = HEADRequest if req.get_method() == 'HEAD' else compat_urllib_request.Request
+ new_req = req_type(
+ req_url, data=req_data, headers=req_headers,
+ origin_req_host=req.origin_req_host, unverifiable=req.unverifiable)
+ if hasattr(req, 'timeout'):
+ new_req.timeout = req.timeout
+ return new_req
+
+
def dict_get(d, key_or_keys, default=None, skip_false_values=True):
if isinstance(key_or_keys, (list, tuple)):
for key in key_or_keys: