From b7e866909a1c96be5965c57289af551869dce2aa Mon Sep 17 00:00:00 2001 From: Sampath Kumar Krishnan Date: Fri, 24 Apr 2020 23:26:06 +0530 Subject: Implement modifyRequestHeaders for Hangouts and document (#137) Co-Authored-By: Mahadevan Sreenivasan --- docs/backend_api.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'docs/backend_api.md') diff --git a/docs/backend_api.md b/docs/backend_api.md index 512912b..dc3bfaa 100644 --- a/docs/backend_api.md +++ b/docs/backend_api.md @@ -5,6 +5,7 @@ Provides a set of helper functions to integrate the recipe into [Ferdi](https:// ## Ferdi Backend Class Methods * [validateUrl](#user-content-validateurl) * [overrideUserAgent](#user-content-overrideuseragent) +* [modifyRequestHeaders](#user-content-modifyrequestheaders) ## Events * [webview events](#user-content-events) @@ -72,6 +73,32 @@ module.exports = Ferdi => class Example extends Ferdi { }; ``` +### modifyRequestHeaders() +Modify headers of HTTP requests sent from a recipe's webview +Any standard HTTP header can be added to the requests. + +#### Returns +`Array` containing objects, each of which should have two properties. +- `headers` - Object containing the header params and their values in key-value format +- `requestFilters` - Array of URL patterns used to filter requests for which the headers need to be added. +Valid URL patterns can be referred from [here](https://www.electronjs.org/docs/api/web-request#webrequestonbeforerequestfilter-listener) + +#### Usage + +```js +// Hangouts Chat integration +module.exports = Ferdi => class HangoutsChat extends Ferdi { + modifyRequestHeaders() { + return [{ + // Adding an origin header for all http requests from this recipe + headers: { 'origin': 'https://chat.google.com' }, + requestFilters: { + urls: ['*://*/*'] + } + }] + } +}; +``` ### Events Ferdi recipes can hook into the [electron webview events](https://electron.atom.io/docs/api/webview-tag/#dom-events) to trigger custom functions. @@ -95,3 +122,4 @@ module.exports = Ferdi => class Tweetdeck extends Ferdi { } }; ``` + -- cgit v1.2.3-54-g00ecf