Skip to content

twilio-run not working behind https proxy #227

@david-amores-anz

Description

@david-amores-anz

Issue Summary

We are using twilio-run behind an https proxy. Running twilio-run deploy hangs at Configuring bare environment and eventually times out with a failed request. This is because the got http client used by serverless-api does not use the HTTP_PROXY environment variable to set an http agent (see sindresorhus/got#79 and sindresorhus/got#7). This makes the requests not issue CONNECTs. This issue is similar to twilio/twilio-cli#223.

Steps to Reproduce

  1. Have a locally running forward proxy
  2. Be on a network behind a https authenticating proxy
  3. Run twilio-run deploy on a twilio function

Reproduce behaviour

This will cause a GET to be sent to the forward proxy.

const got = require('got');
got('https://www.twilio.com')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  })
  .then(function () {
  });

Suggested fix

The recommended fix from got docs is to add an http agent to the got client using the hpagent package.

This will cause a CONNECT to be sent to the forward proxy.

const got = require('got');
const hpagent = require('hpagent');

got('https://www.twilio.com', {
  agent: {
    https: new hpagent.HttpsProxyAgent({
      proxy: process.env.HTTP_PROXY,
    }),
  }
})
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  })
  .then(function () {
  });

The impacted code is in the serverless-api package: https://github.com/twilio-labs/serverless-toolkit/blob/main/packages/serverless-api/src/client.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions