fix: properly handle optional requestHeaders with onBeforeSendHeaders (#29798)
This commit is contained in:
parent
0ad73ac423
commit
bc8cb75e4e
2 changed files with 17 additions and 2 deletions
|
@ -214,8 +214,11 @@ void ReadFromResponse(v8::Isolate* isolate,
|
|||
void ReadFromResponse(v8::Isolate* isolate,
|
||||
gin::Dictionary* response,
|
||||
net::HttpRequestHeaders* headers) {
|
||||
v8::Local<v8::Value> value;
|
||||
if (response->Get("requestHeaders", &value) && value->IsObject()) {
|
||||
headers->Clear();
|
||||
response->Get("requestHeaders", headers);
|
||||
gin::Converter<net::HttpRequestHeaders>::FromV8(isolate, value, headers);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadFromResponse(v8::Isolate* isolate,
|
||||
|
|
|
@ -214,6 +214,18 @@ describe('webRequest module', () => {
|
|||
await ajax(defaultURL);
|
||||
});
|
||||
|
||||
it('leaves headers unchanged when no requestHeaders in callback', async () => {
|
||||
let originalRequestHeaders: Record<string, string>;
|
||||
ses.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
originalRequestHeaders = details.requestHeaders;
|
||||
callback({});
|
||||
});
|
||||
ses.webRequest.onSendHeaders((details) => {
|
||||
expect(details.requestHeaders).to.deep.equal(originalRequestHeaders);
|
||||
});
|
||||
await ajax(defaultURL);
|
||||
});
|
||||
|
||||
it('works with file:// protocol', async () => {
|
||||
const requestHeaders = {
|
||||
Test: 'header'
|
||||
|
|
Loading…
Reference in a new issue