fix: webContents.downloadURL() did not support referer header (#47867)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: xufuhang <576484918@qq.com>
This commit is contained in:
trop[bot] 2025-07-23 16:45:45 +02:00 committed by GitHub
commit 83373c3679
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 0 deletions

View file

@ -2398,6 +2398,13 @@ void WebContents::DownloadURL(const GURL& url, gin::Arguments* args) {
content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame(
web_contents(), url, MISSING_TRAFFIC_ANNOTATION));
for (const auto& [name, value] : headers) {
if (base::ToLowerASCII(name) ==
base::ToLowerASCII(net::HttpRequestHeaders::kReferer)) {
// Setting a Referer header with HTTPS scheme while the download URL's
// scheme is HTTP might lead to download failure.
download_params->set_referrer(GURL(value));
continue;
}
download_params->add_request_header(name, value);
}