Skip to content

Messaging API not using http.Agent (proxy) #719

Closed
@eheikkinen

Description

@eheikkinen

Describe your environment

Operating System version: Windows 10
Firebase SDK version: 8.8.0
Firebase Product: Messaging
Node.js version: v10.15.1
NPM version: 6.4.1

Describe the problem

When using the Messaging API the request do not utilize the setted http.Agent when application was initialized. This results in the requests to fail if sending behind a proxy with the following error:

Error while making request: getaddrinfo ENOTFOUND fcm.googleapis.com fcm.googleapis.com:443. Error code: ENOTFOUND

The authentication does work as it is using the http.Agent properly when passed to:

var firebaseadmin = require("firebase-admin");
firebaseadmin.initializeApp({
    credential: firebaseadmin.credential.cert(accountKey, new HttpsProxyAgent(process.env.http_proxy))
});

Steps to reproduce:

You have to be making request through a proxy server.

Ugly fix

Ugly fix is to modify messaging-api-request.js

var HttpsProxyAgent = require('https-proxy-agent');

and then adding httpAgent to all the requests, e.g.:

FirebaseMessagingRequestHandler.prototype.invokeRequestHandler = function (host, path, requestData) {
    var request = {
        method: FIREBASE_MESSAGING_HTTP_METHOD,
        url: "https://" + host + path,
        data: requestData,
        headers: LEGACY_FIREBASE_MESSAGING_HEADERS,
        timeout: FIREBASE_MESSAGING_TIMEOUT,
        httpAgent: new HttpsProxyAgent(process.env.http_proxy)
    };
    ...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions