Add optional headers to search request

PR #20923.
This commit is contained in:
BurningMop 2024-06-09 03:03:39 -03:00 committed by sledgehammer999
parent 5f31208bf1
commit e60e96cb0e
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2

View file

@ -1,4 +1,4 @@
#VERSION: 1.45 #VERSION: 1.46
# Author: # Author:
# Christophe DUMEZ (chris@qbittorrent.org) # Christophe DUMEZ (chris@qbittorrent.org)
@ -87,9 +87,9 @@ def htmlentitydecode(s):
return re.sub(r'&#x(\w+);', lambda x: chr(int(x.group(1), 16)), t) return re.sub(r'&#x(\w+);', lambda x: chr(int(x.group(1), 16)), t)
def retrieve_url(url): def retrieve_url(url, custom_headers={}):
""" Return the content of the url page as a string """ """ Return the content of the url page as a string """
req = urllib.request.Request(url, headers=headers) req = urllib.request.Request(url, headers={**headers, **custom_headers})
try: try:
response = urllib.request.urlopen(req) response = urllib.request.urlopen(req)
except urllib.error.URLError as errno: except urllib.error.URLError as errno: