Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heroku-client

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heroku-client - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

60

lib/request.js

@@ -1,5 +0,6 @@

var https = require('https'),
agent = new https.Agent({ maxSockets: Number(process.env.HEROKU_CLIENT_MAX_SOCKETS) || 5000 }),
var http = require('http'),
https = require('https'),
concat = require('concat-stream'),
encryptor = require('./encryptor'),
lazy = require('lazy.js'),
memjs = require('memjs'),

@@ -54,3 +55,4 @@ q = require('q'),

Request.prototype.performRequest = function performRequest (cachedResponse) {
var headers,
var defaultRequestOptions,
headers,
key,

@@ -77,14 +79,17 @@ requestOptions,

requestOptions = {
agent: agent,
host: 'api.heroku.com',
port: 443,
path: this.options.path,
auth: ':' + this.options.token,
method: this.options.method || 'GET',
headers: headers
defaultRequestOptions = {
auth: ':' + this.options.token,
method: this.options.method || 'GET',
headers: headers
};
req = https.request(requestOptions, this.handleResponse.bind(this));
requestOptions = this.getRequestOptions(defaultRequestOptions);
if (process.env.HEROKU_HTTP_PROXY_HOST) {
headers['Host'] = 'api.heroku.com';
req = http.request(requestOptions, this.handleResponse.bind(this));
} else {
req = https.request(requestOptions, this.handleResponse.bind(this));
}
this.writeBody(req);

@@ -98,3 +103,28 @@ this.setRequestTimeout(req);

/*
* Set return the correct request options, based on whether or not we're using
* an HTTP proxy.
*/
Request.prototype.getRequestOptions = function getRequestOptions (defaultOptions) {
var requestOptions;
if (process.env.HEROKU_HTTP_PROXY_HOST) {
requestOptions = {
agent: new http.Agent({ maxSockets: Number(process.env.HEROKU_CLIENT_MAX_SOCKETS) || 5000 }),
host : process.env.HEROKU_HTTP_PROXY_HOST,
port : process.env.HEROKU_HTTP_PROXY_PORT || 8080,
path : 'https://api.heroku.com' + this.options.path
}
} else {
requestOptions = {
agent: new https.Agent({ maxSockets: Number(process.env.HEROKU_CLIENT_MAX_SOCKETS) || 5000 }),
host : 'api.heroku.com',
port : 443,
path : this.options.path
}
}
return lazy(requestOptions).merge(defaultOptions).toObject();
};
/*

@@ -185,4 +215,3 @@ * Handle an API response, returning the

Request.prototype.handleFailure = function handleFailure (res, buffer) {
var options = this.options,
callback = this.callback,
var callback = this.callback,
deferred = this.deferred,

@@ -207,4 +236,3 @@ message = 'Expected response to be successful, got ' + res.statusCode,

Request.prototype.handleSuccess = function handleSuccess (res, buffer) {
var options = this.options,
callback = this.callback,
var callback = this.callback,
deferred = this.deferred,

@@ -211,0 +239,0 @@ body = JSON.parse(buffer || '{}');

{
"name": "heroku-client",
"version": "1.0.0",
"version": "1.1.0",
"description": "A wrapper for the Heroku v3 API",

@@ -17,2 +17,7 @@ "main": "./lib/heroku.js",

"author": "Jonathan Clem",
"contributors": [{
"name": "Jonathan Clem"
}, {
"name": "Ray McDermott"
}],
"license": "MIT",

@@ -27,2 +32,3 @@ "bugs": {

"q": "~0.9.6",
"lazy.js" : "~0.3.2",
"memjs": "~0.6.0",

@@ -29,0 +35,0 @@ "inflection": "~1.2.6",

@@ -158,3 +158,3 @@ # heroku-client [![Build Status](https://travis-ci.org/jclem/node-heroku-client.png?branch=master)](https://travis-ci.org/jclem/node-heroku-client)

Documentation for heroku-client is auto-generated from [the resources manifest](https://github.com/heroku/node-heroku-client/blob/development/lib/resources.js).
Documentation for heroku-client is auto-generated from [the API schema](https://github.com/jclem/node-heroku-client/blob/development/lib/schema.js).
Docs are generated like so:

@@ -161,0 +161,0 @@

@@ -1,2 +0,3 @@

var https = require("https"),
var http = require('http'),
https = require('https'),
encryptor = require('../../lib/encryptor');

@@ -49,2 +50,75 @@ Request = require('../../lib/request'),

describe('when using an HTTP proxy', function() {
beforeEach(function() {
process.env.HEROKU_HTTP_PROXY_HOST='localhost:5000';
});
afterEach(function() {
delete process.env.HEROKU_HTTP_PROXY_HOST;
});
it('uses an http agent', function(done) {
makeRequest('/apps', {}, function() {
expect(http.request.mostRecentCall.args[0].host).toBeDefined();
done();
});
});
it('uses the proxy host', function(done) {
makeRequest('/apps', {}, function() {
expect(http.request.mostRecentCall.args[0].host).toEqual('localhost:5000');
done();
});
});
it('uses the full API URL as its path', function(done) {
makeRequest('/apps', {}, function() {
expect(http.request.mostRecentCall.args[0].path).toEqual('https://api.heroku.com/apps');
done();
});
});
describe('when a proxy port is defined', function() {
beforeEach(function() {
process.env.HEROKU_HTTP_PROXY_PORT='8000';
});
afterEach(function() {
delete process.env.HEROKU_HTTP_PROXY_PORT;
});
it('uses the defined port', function(done) {
makeRequest('/apps', {}, function() {
expect(http.request.mostRecentCall.args[0].port).toEqual('8000');;
done()
});
});
});
describe('when a proxy port is not defined', function() {
it('defaults to port 8080', function(done) {
makeRequest('/apps', {}, function() {
expect(http.request.mostRecentCall.args[0].port).toEqual(8080);;
done()
});
});
});
});
describe('when not using an HTTP proxy', function() {
it('uses the API host as its host', function(done) {
makeRequest('/apps', {}, function() {
expect(https.request.mostRecentCall.args[0].host).toEqual('api.heroku.com');
done();
});
});
it('makes a request to port 443', function(done) {
makeRequest('/apps', {}, function() {
expect(https.request.mostRecentCall.args[0].port).toEqual(443);
done()
});
});
});
describe('callbacks and promises', function() {

@@ -72,3 +146,9 @@ it('sends a successful response to the callback', function(done) {

it('rejects a promise when there is an error', function(done) {
it('rejects a promise when there is an error on the request object', function() {
makeRequest('/apps', {}, function (err, res) {
expect(err.message).toEqual('there was an error');
}, { emitError: 'there was an error' });
});
it('rejects a promise when there is an error from an unexpected response', function(done) {
makeRequest('/apps', {}, null, { response: { statusCode: 404 } }).fail(function(err) {

@@ -204,3 +284,6 @@ expect(err.message).toEqual('Expected response to be successful, got 404');

spyOn(https, 'request').andCallFake(function (options, httpsCallback) {
spyOn(https, 'request').andCallFake(fakeRequest);
spyOn(http, 'request').andCallFake(fakeRequest);
function fakeRequest(options, requestCallback) {
if (options.headers.Range !== 'id ]..; max=1000') {

@@ -213,3 +296,3 @@ testOptions.response.headers['next-range'] = undefined;

httpsCallback(res);
requestCallback(res);

@@ -223,2 +306,7 @@ setTimeout(function () {

if (testOptions.emitError) {
req.emit('error', new Error(testOptions.emitError));
req.abort();
}
if (!req.isAborted) res.emit('end');

@@ -228,5 +316,4 @@ }, testOptions.timeout || 0);

return req;
});
}
return Request.request(options, function (err, body) {

@@ -233,0 +320,0 @@ if (callback) callback(err, body);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc