fix: properly handle optional requestHeaders with onBeforeSendHeaders (#29798)

This commit is contained in:
David Sanders 2021-06-21 23:08:52 -07:00 committed by GitHub
parent 0ad73ac423
commit bc8cb75e4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -214,8 +214,11 @@ void ReadFromResponse(v8::Isolate* isolate,
void ReadFromResponse(v8::Isolate* isolate, void ReadFromResponse(v8::Isolate* isolate,
gin::Dictionary* response, gin::Dictionary* response,
net::HttpRequestHeaders* headers) { net::HttpRequestHeaders* headers) {
v8::Local<v8::Value> value;
if (response->Get("requestHeaders", &value) && value->IsObject()) {
headers->Clear(); headers->Clear();
response->Get("requestHeaders", headers); gin::Converter<net::HttpRequestHeaders>::FromV8(isolate, value, headers);
}
} }
void ReadFromResponse(v8::Isolate* isolate, void ReadFromResponse(v8::Isolate* isolate,

View file

@ -214,6 +214,18 @@ describe('webRequest module', () => {
await ajax(defaultURL); 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 () => { it('works with file:// protocol', async () => {
const requestHeaders = { const requestHeaders = {
Test: 'header' Test: 'header'