feat: allow headers to be sent with session.downloadURL()
(#38785)
This commit is contained in:
parent
74d73166d9
commit
e73edb5481
4 changed files with 120 additions and 4 deletions
|
@ -804,10 +804,24 @@ v8::Local<v8::Promise> Session::GetBlobData(v8::Isolate* isolate,
|
|||
return holder->ReadAll(isolate);
|
||||
}
|
||||
|
||||
void Session::DownloadURL(const GURL& url) {
|
||||
auto* download_manager = browser_context()->GetDownloadManager();
|
||||
void Session::DownloadURL(const GURL& url, gin::Arguments* args) {
|
||||
std::map<std::string, std::string> headers;
|
||||
gin_helper::Dictionary options;
|
||||
if (args->GetNext(&options)) {
|
||||
if (options.Has("headers") && !options.Get("headers", &headers)) {
|
||||
args->ThrowTypeError("Invalid value for headers - must be an object");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto download_params = std::make_unique<download::DownloadUrlParameters>(
|
||||
url, MISSING_TRAFFIC_ANNOTATION);
|
||||
|
||||
for (const auto& [name, value] : headers) {
|
||||
download_params->add_request_header(name, value);
|
||||
}
|
||||
|
||||
auto* download_manager = browser_context()->GetDownloadManager();
|
||||
download_manager->DownloadUrl(std::move(download_params));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue