From 560277394e2fdbeaa1491d82eb5265d7f8b41ba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 21 Feb 2021 19:13:39 +0100 Subject: [PATCH] [downloader:http] add 'headers' option (#1322) --- docs/configuration.rst | 10 ++++++++++ gallery_dl/downloader/http.py | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/docs/configuration.rst b/docs/configuration.rst index 50e40f70..d9edf5e0 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -1843,6 +1843,16 @@ Description and adjust their filename extensions if they do not match. +downloader.http.headers +----------------------- +Type + ``object`` +Example + ``{"Accept": "image/webp,*/*", "Referer": "https://example.org/"}`` +Description + Additional HTTP headers to send when downloading files, + + downloader.ytdl.format ---------------------- Type diff --git a/gallery_dl/downloader/http.py b/gallery_dl/downloader/http.py index 8d72dc27..b08aae15 100644 --- a/gallery_dl/downloader/http.py +++ b/gallery_dl/downloader/http.py @@ -31,6 +31,7 @@ class HttpDownloader(DownloaderBase): self.downloading = False self.adjust_extension = self.config("adjust-extensions", True) + self.headers = self.config("headers") self.minsize = self.config("filesize-min") self.maxsize = self.config("filesize-max") self.retries = self.config("retries", extractor._retries) @@ -100,6 +101,9 @@ class HttpDownloader(DownloaderBase): file_size = pathfmt.part_size() if file_size: headers["Range"] = "bytes={}-".format(file_size) + # general headers + if self.headers: + headers.update(self.headers) # file-specific headers extra = pathfmt.kwdict.get("_http_headers") if extra: