diff options
author | Sampath Kumar Krishnan <sampathBlam@users.noreply.github.com> | 2020-04-24 22:20:54 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-24 16:50:54 +0000 |
commit | 35cc75d177064c8154b9d56c549a6335963efe74 (patch) | |
tree | 1fe0a9b476e70bd1baf26dc2564dd5c39324922e | |
parent | Release 5.5.0-gm.2 (#625) (diff) | |
download | ferdium-app-35cc75d177064c8154b9d56c549a6335963efe74.tar.gz ferdium-app-35cc75d177064c8154b9d56c549a6335963efe74.tar.zst ferdium-app-35cc75d177064c8154b9d56c549a6335963efe74.zip |
Add modifyRequestHeaders, enable properly setting headers for services
Co-Authored-By: Mahadevan Sreenivasan <mahadevan_sv@yahoo.com>
-rw-r--r-- | src/index.js | 18 | ||||
-rw-r--r-- | src/models/Service.js | 15 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/index.js b/src/index.js index e5f678759..027884826 100644 --- a/src/index.js +++ b/src/index.js | |||
@@ -3,6 +3,7 @@ import { | |||
3 | BrowserWindow, | 3 | BrowserWindow, |
4 | shell, | 4 | shell, |
5 | ipcMain, | 5 | ipcMain, |
6 | session, | ||
6 | } from 'electron'; | 7 | } from 'electron'; |
7 | import isDevMode from 'electron-is-dev'; | 8 | import isDevMode from 'electron-is-dev'; |
8 | import fs from 'fs-extra'; | 9 | import fs from 'fs-extra'; |
@@ -394,6 +395,23 @@ ipcMain.on('feature-basic-auth-credentials', (e, { user, password }) => { | |||
394 | authCallback = noop; | 395 | authCallback = noop; |
395 | }); | 396 | }); |
396 | 397 | ||
398 | |||
399 | ipcMain.on('modifyRequestHeaders', (e, { modifiedRequestHeaders, serviceId }) => { | ||
400 | debug('Received modifyRequestHeaders', modifiedRequestHeaders, serviceId); | ||
401 | modifiedRequestHeaders.forEach((headerFilterSet) => { | ||
402 | const { headers, requestFilters } = headerFilterSet; | ||
403 | session.fromPartition(`persist:service-${serviceId}`).webRequest.onBeforeSendHeaders(requestFilters, (details, callback) => { | ||
404 | for (const key in headers) { | ||
405 | if (Object.prototype.hasOwnProperty.call(headers, key)) { | ||
406 | const value = headers[key]; | ||
407 | details.requestHeaders[key] = value; | ||
408 | } | ||
409 | } | ||
410 | callback({ requestHeaders: details.requestHeaders }); | ||
411 | }); | ||
412 | }); | ||
413 | }); | ||
414 | |||
397 | ipcMain.on('feature-basic-auth-cancel', () => { | 415 | ipcMain.on('feature-basic-auth-cancel', () => { |
398 | debug('Cancel basic auth'); | 416 | debug('Cancel basic auth'); |
399 | 417 | ||
diff --git a/src/models/Service.js b/src/models/Service.js index 2f2b4572d..5b3ad7bd8 100644 --- a/src/models/Service.js +++ b/src/models/Service.js | |||
@@ -1,4 +1,5 @@ | |||
1 | import { autorun, computed, observable } from 'mobx'; | 1 | import { autorun, computed, observable } from 'mobx'; |
2 | import { ipcRenderer } from 'electron'; | ||
2 | import normalizeUrl from 'normalize-url'; | 3 | import normalizeUrl from 'normalize-url'; |
3 | import path from 'path'; | 4 | import path from 'path'; |
4 | 5 | ||
@@ -224,9 +225,23 @@ export default class Service { | |||
224 | return ua; | 225 | return ua; |
225 | } | 226 | } |
226 | 227 | ||
228 | |||
227 | initializeWebViewEvents({ handleIPCMessage, openWindow, stores }) { | 229 | initializeWebViewEvents({ handleIPCMessage, openWindow, stores }) { |
228 | const webContents = this.webview.getWebContents(); | 230 | const webContents = this.webview.getWebContents(); |
229 | 231 | ||
232 | // If the recipe has implemented modifyRequestHeaders, | ||
233 | // Send those headers to ipcMain so that it can be set in session | ||
234 | if (typeof this.recipe.modifyRequestHeaders === 'function') { | ||
235 | const modifiedRequestHeaders = this.recipe.modifyRequestHeaders(); | ||
236 | debug(this.name, 'modifiedRequestHeaders', modifiedRequestHeaders); | ||
237 | ipcRenderer.send('modifyRequestHeaders', { | ||
238 | modifiedRequestHeaders, | ||
239 | serviceId: this.id, | ||
240 | }); | ||
241 | } else { | ||
242 | debug(this.name, 'modifyRequestHeaders is not defined in the recipe'); | ||
243 | } | ||
244 | |||
230 | const handleUserAgent = (url, forwardingHack = false) => { | 245 | const handleUserAgent = (url, forwardingHack = false) => { |
231 | if (url.startsWith('https://accounts.google.com')) { | 246 | if (url.startsWith('https://accounts.google.com')) { |
232 | if (!this.chromelessUserAgent) { | 247 | if (!this.chromelessUserAgent) { |