Skip to content

Always use http-agent for hooks and triggers #4800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/Controllers/HooksController.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ export class HooksController {
_applicationId:string;
_webhookKey:string;
database: any;
keepAlive: boolean;

constructor(applicationId:string, databaseController, webhookKey, keepAlive) {
constructor(applicationId:string, databaseController, webhookKey) {
this._applicationId = applicationId;
this._webhookKey = webhookKey;
this.database = databaseController;
this.keepAlive = keepAlive;
}

load() {
Expand Down Expand Up @@ -93,7 +91,7 @@ export class HooksController {
}

addHookToTriggers(hook) {
var wrappedFunction = wrapToHTTPRequest(hook, this._webhookKey, this.keepAlive);
var wrappedFunction = wrapToHTTPRequest(hook, this._webhookKey);
wrappedFunction.url = hook.url;
if (hook.className) {
triggers.addTrigger(hook.triggerName, hook.className, wrappedFunction, this._applicationId)
Expand Down Expand Up @@ -167,7 +165,7 @@ export class HooksController {
}
}

function wrapToHTTPRequest(hook, key, keepAlive) {
function wrapToHTTPRequest(hook, key) {
return (req, res) => {
const jsonBody = {};
for (var i in req) {
Expand All @@ -188,10 +186,8 @@ function wrapToHTTPRequest(hook, key, keepAlive) {
body: JSON.stringify(jsonBody),
};

if (keepAlive) {
const agent = hook.url.startsWith('https') ? HTTPAgents['https'] : HTTPAgents['http'];
jsonRequest.agent = agent;
}
const agent = hook.url.startsWith('https') ? HTTPAgents['https'] : HTTPAgents['http'];
jsonRequest.agent = agent;

if (key) {
jsonRequest.headers['X-Parse-Webhook-Key'] = key;
Expand Down
3 changes: 1 addition & 2 deletions src/Controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ export function getHooksController(options: ParseServerOptions, databaseControll
const {
appId,
webhookKey,
hookKeepAlive,
} = options;
return new HooksController(appId, databaseController, webhookKey, hookKeepAlive);
return new HooksController(appId, databaseController, webhookKey);
}

interface PushControlling {
Expand Down
5 changes: 0 additions & 5 deletions src/Options/Definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,6 @@ module.exports.ParseServerOptions = {
"env": "PARSE_SERVER_LIVE_QUERY_SERVER_OPTIONS",
"help": "Live query server configuration options (will start the liveQuery server)",
"action": parsers.objectParser
},
"hookKeepAlive": {
"env": "PARSE_SERVER_HOOK_KEEP_ALIVE",
"help": "Keep hook HTTP connections alive",
"action": parsers.booleanParser
}
};
module.exports.CustomPagesOptions = {
Expand Down
2 changes: 0 additions & 2 deletions src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ export interface ParseServerOptions {
startLiveQueryServer: ?boolean;
/* Live query server configuration options (will start the liveQuery server) */
liveQueryServerOptions: ?LiveQueryServerOptions;
/* Keep hook HTTP connections alive */
hookKeepAlive: ?boolean;

__indexBuildCompletionCallbackForTests: ?()=>void;
}
Expand Down