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 --- all.json | 2 +- archives/hangoutschat.tar.gz | Bin 113884 -> 114002 bytes docs/backend_api.md | 28 ++++++++++++++++++++++++++++ uncompressed/hangoutschat/index.js | 10 ++++++++++ uncompressed/hangoutschat/package.json | 2 +- 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/all.json b/all.json index e8a79a2..9b4acca 100644 --- a/all.json +++ b/all.json @@ -345,7 +345,7 @@ "featured": false, "id": "hangoutschat", "name": "Hangouts Chat", - "version": "1.2.3", + "version": "1.3.0", "icons": { "png": "https://cdn.jsdelivr.net/gh/getferdi/recipes/uncompressed/hangoutschat/icon.png", "svg": "https://cdn.jsdelivr.net/gh/getferdi/recipes/uncompressed/hangoutschat/icon.svg" diff --git a/archives/hangoutschat.tar.gz b/archives/hangoutschat.tar.gz index b1fdc9c..39d9ae0 100644 Binary files a/archives/hangoutschat.tar.gz and b/archives/hangoutschat.tar.gz differ 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 { } }; ``` + diff --git a/uncompressed/hangoutschat/index.js b/uncompressed/hangoutschat/index.js index 95e7fa5..819e06b 100644 --- a/uncompressed/hangoutschat/index.js +++ b/uncompressed/hangoutschat/index.js @@ -3,6 +3,16 @@ var os = require('os') // just pass through Franz module.exports = Franz => class HangoutsChat extends Franz { + // Method to add headers to requests from Hangouts Chat's webview + modifyRequestHeaders() { + return [{ + headers: { 'origin': 'https://chat.google.com' }, + requestFilters: { + urls: ['*://*/*'] + } + }] + } + overrideUserAgent() { if (os.platform() == 'linux') return "Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0" diff --git a/uncompressed/hangoutschat/package.json b/uncompressed/hangoutschat/package.json index 40b0357..bcc58f9 100644 --- a/uncompressed/hangoutschat/package.json +++ b/uncompressed/hangoutschat/package.json @@ -1,7 +1,7 @@ { "id": "hangoutschat", "name": "Hangouts Chat", - "version": "1.2.3", + "version": "1.3.0", "description": "Hangouts Chat", "main": "index.js", "author": "Stefan Malzner and Iván López (ilopmar)", -- cgit v1.2.3-54-g00ecf