New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

http-request

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-request - npm Package Compare versions

Comparing version 0.6.3 to 0.7.0

config/jshint.json

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## v0.7
* [MAY BREAK COMPAT] The Error objects thrown on wrong argument types were changed to TypeError. Standardised message output for these errors.
* Fixed the client crash when noRedirect is used with a response that doesn't redirect.
* Migrated from jslint to jshint.
* Removed the warning about the deprecated options.bufferType.
## v0.6.3

@@ -2,0 +8,0 @@ * New option: auth. Defines the HTTP Authentication parameters. Currently it only supports Basic authentication.

11

lib/main.js

@@ -8,3 +8,2 @@ 'use strict';

/* core modules */
var util = require('util');
var http = require('http');

@@ -39,3 +38,3 @@ var fs = require('fs');

var request = exports.createHttpClient(options);
tools.checkCallback(callback, request.options.url);
tools.checkType('callback', callback, 'function');

@@ -74,5 +73,3 @@ request.send(function(err, res) {

// save to file
if (typeof file !== 'string') {
throw tools.formatError('Expecting a file path for saving the object from URL: %s.', options.url);
}
tools.checkType('file', file, 'string');

@@ -179,3 +176,3 @@ request.saveFile(file, function(err, stdResult) {

var request = exports.createHttpClient(options);
tools.checkCallback(callback, request.options.url);
tools.checkType('callback', callback, 'function');

@@ -549,2 +546,2 @@ request.send(function(err, res) {

* @param {module:request~stdResult} result The standard result object if error is null
*/
*/

@@ -27,17 +27,15 @@ 'use strict';

*
* @throws {options.url} The options object requires an input URL value.
* @throws {options.method} The options object requres a HTTP method value.
* @throws {options.maxBody} Invalid options.maxBody specification. Expecting a proper integer value.
* @throws {options.progress} Expecting a function as progress callback.
* @throws {options.auth} Expecting an Object for the auth option.
* @throws {options.auth.type} Unknown type for the auth option.
* @throws {TypeError} Parameter 'options' must be an object, not $actualType
* @throws {TypeError} Parameter 'options.url' must be a string, not $actualType
* @throws {TypeError} Parameter 'options.method' must be a string, not $actualType
* @throws {TypeError} Parameter 'options.maxBody' must be a number, not $actualType
* @throws {TypeError} Parameter 'options.progress' must be a function, not $actualType
* @throws {TypeError} Parameter 'options.auth' must be an object, not $actualType
* @throws {Error} Invalid value for option.auth.type.
*/
function Request(options) {
if (!options.url) {
throw new Error('The options object requires an input URL value.');
}
tools.checkType('options', options, 'object');
tools.checkType('options.url', options.url, 'string');
tools.checkType('options.method', options.method, 'string');
if (!options.method) {
throw new Error('The options object requres a HTTP method value.');
}
options.method = options.method.toUpperCase();

@@ -82,20 +80,12 @@

if (this.options.maxBody) {
tools.checkType('options.maxBody', this.options.maxBody, 'number');
this.options.maxBody = tools.absInt(this.options.maxBody);
if (!this.options.maxBody) {
throw new Error('Invalid options.maxBody specification. Expecting a proper integer value.');
}
}
if (this.options.progress && typeof this.options.progress !== 'function') {
throw new Error('Expecting a function as progress callback.');
if (this.options.progress) {
tools.checkType('options.progress', this.options.progress, 'function');
}
if (this.options.bufferType) {
console.error('Warning: the bufferType option is deprecated. There is only a single buffer implementation using the node.js Buffer object.');
}
if (this.options.auth) {
if (typeof this.options.auth !== 'object') {
throw new Error('Expecting an Object for the auth option.');
}
tools.checkType('options.auth', this.options.auth, 'object');

@@ -108,3 +98,3 @@ switch (this.options.auth.type) {

default:
throw new Error('Unknown type for the auth option.');
throw new Error('Invalid value for option.auth.type.');
}

@@ -246,3 +236,3 @@ }

*
* @throws {callback} Expecting a function for callback on URL {@link module:request~Request} options.url.
* @throws {TypeError} Parameter 'callback' must be a function, not $actualType
*/

@@ -262,5 +252,3 @@ Request.prototype.send = function(callback) {

if (typeof callback !== 'function') {
throw tools.formatError('Expecting a function for callback on URL %s.', this.options.url);
}
tools.checkType('callback', callback, 'function');

@@ -521,3 +509,5 @@ if (!this.options.proxy) {

if (this.options.noRedirect) {
// This needs to be enabled only if there's an actual redirect response
// for a call that uses the noRedirect option
if (this.options.noRedirect && (ret.code === 301 || ret.code === 302 || ret.code === 303 || ret.code === 307)) {
this.prepareRedirectUrl();

@@ -783,3 +773,6 @@

* @property {Buffer|Stream} reqBody Optional; the contents of the request body for PUT, POST, etc. requests. Must be a Buffer or a Readable Stream instance. For Buffers, the content-length is Buffer.lenght. For a Readable Stream you must pass a content-length header, unless you're building a POST request with the [form-data](https://github.com/felixge/node-form-data) module. The library makes no assumptions about the content-type header, unless you're building a form with form-data
* @property {module:request~auth} auth Optional; an object describing the authentication information. Currently it only implements HTTP Basic Authentication. The HTTP Basic Authentication was already supported by passing the username:password to the URL itself. This option provides a more API-friendly approach and it adds the basics for implementing HTTP Digest Authentication.
* @property {Object} auth Optional; an Object that contains the authentication information. Currently it only implements HTTP Basic Authentication. The HTTP Basic Authentication was already supported by passing the username:password to the URL itself. This option provides a more API-friendly approach and it adds the basics for implementing HTTP Digest Authentication.
* @property {String} auth.type The authentication type; Supported value: basic
* @property {String} auth.username The HTTP Authentication username
* @property {String} auth.password The HTTP Authentication password
*/

@@ -846,12 +839,2 @@

* @property {String} url Optional, passed if there was a HTTP redirect. Contains the URL of the resource that returned a succesful status code.
*/
/**
* Describes the auth Object
*
* @typedef module:request~auth
* @type {Object}
* @property {String} type The HTTP Authentication type. Currently the only accepted value is: basic.
* @property {String} username The username
* @property {String} password The password
*/
*/

@@ -8,2 +8,12 @@ 'use strict';

/**
* Checks if the letter is a vowel
*
* @private
* @param {String} c The character to check
*/
var isVowel = function(c) {
return ['a', 'e', 'i', 'o', 'u'].indexOf(c) !== -1;
};
/**
* Creates the shorthand options object for specific HTTP method

@@ -34,17 +44,2 @@ *

/**
* Checks the callback argument for proper type
*
* @private
* @param {Mixed} callback Supposedly a Function which is what we're validating here
* @param {String} url The input URL for better debugging of the user error, part of the Error message
*
* @throws {callback} Expecting a function for the callback argument for URL: url
*/
exports.checkCallback = function(callback, url) {
if (typeof callback !== 'function') {
throw exports.formattedError('Expecting a function for the callback argument for URL: %s.', url);
}
};
/**
* util.debug wrapper. Outputs only when NODE_ENV=development

@@ -72,2 +67,17 @@ *

/**
* Check the type of a param
*
* @private
* @param {Mixed} param The param which has the wrong type
* @param {String} paramType The param expected type
* @returns {Error} The TypeError object with the message wrapped by [util.format](http://nodejs.org/api/util.html#util_util_format_format)
*/
exports.checkType = function(name, param, paramType) {
if (typeof param !== paramType) {
var article = isVowel(paramType.charAt(0)) ? 'an' : 'a';
throw new TypeError(util.format('Parameter \'%s\' must be %s %s, not %s', name, article, paramType, typeof param));
}
};
/*jslint bitwise:true*/

@@ -122,2 +132,2 @@ /**

return qs.stringify(obj);
};
};
{
"name": "http-request",
"version": "0.6.3",
"version": "0.7.0",
"main": "./lib/main.js",

@@ -17,3 +17,3 @@ "description": "General purpose HTTP / HTTPS client for node.js. Supports transparent gzip / deflate decoding.",

"js-beautify": ">= 0.4.2",
"jslint": ">= 0.1.9",
"jshint": ">= 2.5.6",
"multiparty": ">= 3.0.0"

@@ -60,2 +60,2 @@ },

}
}
}

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

module.exports = "-----BEGIN CERTIFICATE-----\n\
module.exports = '-----BEGIN CERTIFICATE-----\n\
MIIDWTCCAsKgAwIBAgIJAK2xvkb3AFXnMA0GCSqGSIb3DQEBBQUAMHwxCzAJBgNV\n\

@@ -21,2 +21,2 @@ BAYTAlJPMRMwEQYDVQQIEwpTb21lLVN0YXRlMQ0wCwYDVQQKEwRIb21lMQ0wCwYD\n\

-----END CERTIFICATE-----\n\
";
\n';

@@ -30,3 +30,3 @@ 'use strict';

var secureServerOptions = {
key: "-----BEGIN RSA PRIVATE KEY-----\n\
key: '-----BEGIN RSA PRIVATE KEY-----\n\
MIICXAIBAAKBgQCqU3qR60Pgojh8HjO3+ttmgZVj6l5Ai0PHscCUq7q72vrgJVjz\n\

@@ -46,4 +46,4 @@ LqfOz2K182MxACwh5oYklqhSuL+7j+GvXRVCoq7Y2zE6P/PphEGhVwgS1fg034S4\n\

-----END RSA PRIVATE KEY-----\n\
",
cert: "-----BEGIN CERTIFICATE-----\n\
\n',
cert: '-----BEGIN CERTIFICATE-----\n\
MIIDAjCCAmugAwIBAgIJAK2xvkb3AFXoMA0GCSqGSIb3DQEBBQUAMHwxCzAJBgNV\n\

@@ -67,3 +67,3 @@ BAYTAlJPMRMwEQYDVQQIEwpTb21lLVN0YXRlMQ0wCwYDVQQKEwRIb21lMQ0wCwYD\n\

-----END CERTIFICATE-----\n\
"
\n'
};

@@ -586,2 +586,2 @@

});
};
};

@@ -9,2 +9,2 @@ // launches the test servers into a persistent state

});
}
}

@@ -6,7 +6,5 @@ 'use strict';

var client = require('../');
var config = require('../package.json');
var common = require('./common.js');
var util = require('util');
var assert = require('chai').assert;

@@ -24,3 +22,3 @@

describe('DELETE Hello World Buffer - plain', function() {
describe('DELETE: Hello World Buffer - plain', function() {
it('should pass "Hello World" buffer', function(done) {

@@ -45,3 +43,3 @@ client.delete({

describe('DELETE Hello World Buffer - gzip', function() {
describe('DELETE: Hello World Buffer - gzip', function() {
it('should pass "Hello World" buffer', function(done) {

@@ -65,3 +63,3 @@ client.delete({

describe('DELETE Hello World Buffer - deflate', function() {
describe('DELETE: Hello World Buffer - deflate', function() {
it('should pass "Hello World" buffer', function(done) {

@@ -85,3 +83,3 @@ client.delete({

describe('DELETE with no content', function() {
describe('DELETE: with no content', function() {
it('should return a 204 response', function(done) {

@@ -107,2 +105,2 @@ client.delete('http://127.0.0.1:' + common.options.port + '/no-content', function(err, res) {

});
});

@@ -13,2 +13,4 @@ 'use strict';

var util = require('util');
var domain = require('domain');
var assert = require('chai').assert;

@@ -26,7 +28,8 @@

describe('GET Hello World Buffer - plain', function() {
describe('GET: Hello World Buffer - plain', function() {
it('should pass "Hello World" buffer', function(done) {
client.get({
url: 'http://127.0.0.1:' + common.options.port + '/hello-plain',
noCompress: true
noCompress: true,
noRedirect: true
}, function(err, res) {

@@ -47,3 +50,3 @@ assert.isNull(err, 'we have an error');

describe('GET Hello World Buffer - gzip', function() {
describe('GET: Hello World Buffer - gzip', function() {
it('should pass "Hello World" buffer', function(done) {

@@ -67,3 +70,3 @@ client.get({

describe('GET Hello World Buffer - deflate', function() {
describe('GET: Hello World Buffer - deflate', function() {
it('should pass "Hello World" buffer', function(done) {

@@ -87,3 +90,3 @@ client.get({

describe('GET Basic Authentication', function() {
describe('GET: Basic Authentication', function() {
it('should pass back the basic authentication', function(done) {

@@ -114,3 +117,3 @@ var url = u.format({

describe('GET Basic Authentication with auth option', function() {
describe('GET: Basic Authentication with auth option', function() {
it('should pass back the basic authentication', function(done) {

@@ -141,5 +144,5 @@ var basicAuth = {

describe('GET invalid type for the auth option', function() {
it('should throw an Error', function(done) {
var throws = function() {
describe('GET: invalid type for the auth option', function() {
it('should throw a TypeError', function(done) {
assert.throws(function() {
client.get({

@@ -151,6 +154,4 @@ url: 'http://127.0.0.1:' + common.options.port + '/basic-auth',

});
};
}, TypeError, 'Parameter \'options.auth\' must be an object, not string');
assert.throws(throws, Error, 'Expecting an Object for the auth option.');
done();

@@ -160,5 +161,5 @@ });

describe('GET invalid option.auth.type', function() {
describe('GET: invalid option.auth.type', function() {
it('should throw an Error', function(done) {
var throws = function() {
assert.throws(function() {
client.get({

@@ -172,6 +173,4 @@ url: 'http://127.0.0.1:' + common.options.port + '/basic-auth',

});
};
}, Error, 'Invalid value for option.auth.type.');
assert.throws(throws, Error, 'Unknown type for the auth option.');
done();

@@ -181,3 +180,3 @@ });

describe('GET broken DNS name over HTTP', function() {
describe('GET: broken DNS name over HTTP', function() {
it('should fail with an error passed back to the completion callback', function(done) {

@@ -195,3 +194,3 @@ client.get('http://.foo.bar/', function(err, res) {

describe('GET broken DNS name over HTTPS', function() {
describe('GET: broken DNS name over HTTPS', function() {
it('should fail with an error passed back to the completion callback', function(done) {

@@ -209,8 +208,8 @@ client.get('https://.foo.bar/', function(err, res) {

describe('GET DNS error', function() {
describe('GET: DNS error', function() {
it('should fail with an error passed back to the completion callback', function(done) {
client.get('http://foo.bar/', function(err, res) {
client.get('http://wibble.wobble/', function(err, res) {
assert.instanceOf(err, Error, 'the error is an Error instance');
assert.strictEqual(err.code, 'ENOTFOUND');
assert.strictEqual(err.url, 'http://foo.bar/');
assert.strictEqual(err.url, 'http://wibble.wobble/');

@@ -224,3 +223,3 @@ assert.isUndefined(res, 'we have a response');

describe('GET header reflect', function() {
describe('GET: header reflect', function() {
it('should pass back the header foo sent from the client', function(done) {

@@ -244,5 +243,5 @@ client.get({

describe('GET with invalid maxBody', function() {
it('should throw an Error', function(done) {
var throws = function() {
describe('GET: with invalid maxBody', function() {
it('should throw a TypeError', function(done) {
assert.throws(function() {
client.get({

@@ -254,6 +253,4 @@ url: 'http://127.0.0.1:' + common.options.port + '/',

});
};
}, TypeError, 'Parameter \'options.maxBody\' must be a number, not string');
assert.throws(throws, Error, 'Invalid options.maxBody specification. Expecting a proper integer value.');
done();

@@ -263,5 +260,5 @@ });

describe('GET with invalid progress', function() {
it('should throw an Error', function(done) {
var throws = function() {
describe('GET: with invalid progress', function() {
it('should throw a TypeError', function(done) {
assert.throws(function() {
client.get({

@@ -273,6 +270,4 @@ url: 'http://127.0.0.1:' + common.options.port + '/',

});
};
}, TypeError, 'Parameter \'options.progress\' must be a function, not string');
assert.throws(throws, Error, 'Expecting a function as progress callback.');
done();

@@ -282,3 +277,3 @@ });

describe('GET without protocol prefix', function() {
describe('GET: without protocol prefix', function() {
it('should work fine by prepending http:// to the URL', function(done) {

@@ -298,3 +293,3 @@ client.get('127.0.0.1:' + common.options.port + '/no-protocol-prefix', function(err, res) {

describe('GET ranged content', function() {
describe('GET: ranged content', function() {
it('should return just part of the content', function(done) {

@@ -322,3 +317,3 @@ client.get({

describe('GET with redirect', function() {
describe('GET: with redirect', function() {
it('should redirect succesfully', function(done) {

@@ -344,3 +339,3 @@ client.get({

describe('GET with progress callback', function() {
describe('GET: with progress callback', function() {
it('should call the progress callback', function(done) {

@@ -370,3 +365,3 @@ client.get({

describe('GET over HTTPS with SSL validation', function() {
describe('GET: over HTTPS with SSL validation', function() {
it('should verify succesfully the connection', function(done) {

@@ -392,12 +387,10 @@ client.get({

describe('GET without url', function() {
describe('GET: without url', function() {
it('should throw an error', function(done) {
var throws = function() {
assert.throws(function() {
client.get({}, function(err) {
assert.ifError(err);
});
};
}, TypeError, 'Parameter \'options.url\' must be a string, not undefined');
assert.throws(throws, Error, 'The options object requires an input URL value.');
done();

@@ -407,3 +400,3 @@ });

describe('GET 404', function() {
describe('GET: 404 response', function() {
it('should buffer the error document', function(done) {

@@ -426,3 +419,3 @@ var url = 'http://127.0.0.1:' + common.options.port + '/not-found';

describe('GET with redirect loop', function() {
describe('GET: with redirect loop', function() {
it('should detect the condition and pass the error argument to the completion callback', function(done) {

@@ -445,3 +438,3 @@ var url = 'http://127.0.0.1:' + common.options.port + '/redirect-loop';

describe('GET with maxBody limit', function() {
describe('GET: with maxBody limit', function() {
it('should detect that the buffer is overflowing the user limit', function(done) {

@@ -466,3 +459,3 @@ var url = 'http://127.0.0.1:' + common.options.port + '/max-body';

describe('GET with null argument for the file argument', function() {
describe('GET: with null argument for the file argument', function() {
it('should simulate writing the file /dev/null in a cross platform way', function(done) {

@@ -484,3 +477,3 @@ client.get('http://127.0.0.1:' + common.options.port + '/redirect', null, function(err, res) {

describe('GET with gzipped response without being requested', function() {
describe('GET: with gzipped response without being requested', function() {
it('should return gzipped content without being requested', function(done) {

@@ -503,3 +496,3 @@ client.get({

describe('GET response saved to file', function() {
describe('GET: response saved to file', function() {
it('should save the response body to a file', function(done) {

@@ -533,3 +526,3 @@ client.get('http://127.0.0.1:' + common.options.port + '/save-to-file', 'hello.txt', function(err, res) {

describe('GET stream passed to client', function() {
describe('GET: stream passed to client', function() {
it('should pass back a readable stream to the client', function(done) {

@@ -569,3 +562,3 @@ client.get({

describe('GET with gzip compressed stream passed to client', function() {
describe('GET: with gzip compressed stream passed to client', function() {
it('should pass back a decompressed readable stream to the client', function(done) {

@@ -604,3 +597,3 @@ client.get({

describe('GET with error passed to the completion callback by the fs module', function() {
describe('GET: with error passed to the completion callback by the fs module', function() {
it('should pass back an error from the fs module', function(done) {

@@ -642,3 +635,3 @@ var path = 'world.txt';

if (!process.env.TRAVIS_NODE_VERSION) {
describe('GET with overflowing error document', function() {
describe('GET: with overflowing error document', function() {
it('should detect the situation and act accordingly', function(done) {

@@ -664,10 +657,8 @@ client.get({

describe('GET with bad callback', function() {
describe('GET: with bad callback', function() {
it('should throw and error', function(done) {
var throws = function() {
assert.throws(function() {
client.get('http://127.0.0.1:' + common.options.port + '/');
};
}, TypeError, 'Parameter \'callback\' must be a function, not undefined');
assert.throws(throws, Error, 'Expecting a function for the callback argument for URL: ' + 'http://127.0.0.1:' + common.options.port + '/');
done();

@@ -677,3 +668,3 @@ });

describe('GET with standard user agent', function() {
describe('GET: with standard user agent', function() {
it('should pass the standard user-agent header', function(done) {

@@ -692,3 +683,3 @@ client.get('http://127.0.0.1:' + common.options.port + '/user-agent-reflect', function(err, res) {

describe('GET with user agent turned off', function() {
describe('GET: with user agent turned off', function() {
it('should not pass the user-agent header back', function(done) {

@@ -710,3 +701,3 @@ client.get({

describe('GET with noRedirect', function() {
describe('GET: with noRedirect', function() {
it('should read the status code, headers, and body from the redirect response', function(done) {

@@ -729,3 +720,3 @@ client.get({

describe('GET with proxy', function() {
describe('GET: with proxy', function() {
it('should succeed', function(done) {

@@ -751,3 +742,3 @@ client.get({

describe('GET with no content', function() {
describe('GET: with no content', function() {
it('should return a 204 response', function(done) {

@@ -767,3 +758,3 @@ client.get('http://127.0.0.1:' + common.options.port + '/no-content', function(err, res) {

describe('GET with not modified', function() {
describe('GET: with not modified', function() {
it('should return a 304 response', function(done) {

@@ -788,3 +779,3 @@ client.get({

describe('GET to not-modified without if-modified-since', function() {
describe('GET: to not-modified without if-modified-since', function() {
it('should return a 200 response', function(done) {

@@ -804,3 +795,3 @@ client.get('http://127.0.0.1:' + common.options.port + '/not-modified', function(err, res) {

describe('GET to proxy to use-proxy', function() {
describe('GET: to proxy to use-proxy', function() {
it('should go through the proxy to the use-proxy actual response', function(done) {

@@ -826,3 +817,3 @@ client.get({

describe('GET to use-proxy', function() {
describe('GET: to use-proxy', function() {
it('should receive the response via a http-proxy', function(done) {

@@ -845,3 +836,3 @@ client.get({

describe('GET with broken gzip encoding', function() {
describe('GET: with broken gzip encoding', function() {
it('should reissue the request without the accept-encoding: gzip,deflate header', function(done) {

@@ -860,3 +851,3 @@ client.get('http://127.0.0.1:' + common.options.port + '/break-compression', function(err, res) {

describe('GET with broken encoding saved to file', function() {
describe('GET: with broken encoding saved to file', function() {
it('should reissue the request without the accept-encoding: gzip,deflate header', function(done) {

@@ -889,3 +880,23 @@ client.get('http://127.0.0.1:' + common.options.port + '/break-compression', 'foo.txt', function(err, res) {

describe('GET with redirect and defined host header into the request', function() {
// Catching TypeError in node.js v0.8.x is dodgy
if (process.version.substring(0, 5) !== 'v0.8.') {
describe('GET: with invalid type for file', function() {
it('should throw a TypeError', function(done) {
var dom = domain.create();
dom.on('error', function(err) {
assert.instanceOf(err, TypeError, 'we got a TypeError');
assert.strictEqual(err.message, 'Parameter \'file\' must be a string, not number', 'we got the proper message');
done();
});
dom.run(function() {
client.get('http://127.0.0.1:' + common.options.port + '/save-to-file', 0, function() {});
});
});
});
}
describe('GET: with redirect and defined host header into the request', function() {
it('should keep the host header for relative redirects', function(done) {

@@ -892,0 +903,0 @@ client.get({

@@ -23,7 +23,8 @@ 'use strict';

describe('HEAD Hello World - plain', function() {
describe('HEAD: Hello World - plain', function() {
it('should pass the response headers', function(done) {
client.head({
url: 'http://127.0.0.1:' + common.options.port + '/hello-plain',
noCompress: true
noCompress: true,
noRedirect: true
}, function(err, res) {

@@ -42,3 +43,3 @@ assert.isNull(err, 'we have an error');

describe('HEAD Hello World - gzip', function() {
describe('HEAD: Hello World - gzip', function() {
it('should pass the response headers', function(done) {

@@ -61,3 +62,3 @@ client.head({

describe('HEAD Hello World - deflate', function() {
describe('HEAD: Hello World - deflate', function() {
it('should pass the response headers', function(done) {

@@ -80,3 +81,3 @@ client.head({

describe('HEAD redirect without location header', function() {
describe('HEAD: redirect without location header', function() {
it('should return the error argument', function(done) {

@@ -99,3 +100,3 @@ client.head({

describe('HEAD broken DNS name over HTTP', function() {
describe('HEAD: broken DNS name over HTTP', function() {
it('should fail with an error passed back to the completion callback', function(done) {

@@ -113,3 +114,3 @@ client.head('http://.foo.bar/', function(err, res) {

describe('HEAD broken DNS name over HTTPS', function() {
describe('HEAD: broken DNS name over HTTPS', function() {
it('should fail with an error passed back to the completion callback', function(done) {

@@ -127,8 +128,8 @@ client.head('https://.foo.bar/', function(err, res) {

describe('HEAD DNS error', function() {
describe('HEAD: DNS error', function() {
it('should fail with an error passed back to the completion callback', function(done) {
client.head('http://foo.bar/', function(err, res) {
client.head('http://wibble.wobble/', function(err, res) {
assert.instanceOf(err, Error, 'the error is an Error instance');
assert.strictEqual(err.code, 'ENOTFOUND');
assert.strictEqual(err.url, 'http://foo.bar/');
assert.strictEqual(err.url, 'http://wibble.wobble/');

@@ -142,3 +143,3 @@ assert.isUndefined(res, 'we have a response');

describe('HEAD header reflect', function() {
describe('HEAD: header reflect', function() {
it('should pass back the header foo sent from the client', function(done) {

@@ -161,3 +162,3 @@ client.head({

describe('HEAD without protocol prefix', function() {
describe('HEAD: without protocol prefix', function() {
it('should work fine by prepending http:// to the URL', function(done) {

@@ -176,3 +177,3 @@ client.head('127.0.0.1:' + common.options.port + '/no-protocol-prefix', function(err, res) {

describe('HEAD with redirect', function() {
describe('HEAD: with redirect', function() {
it('should redirect succesfully', function(done) {

@@ -194,3 +195,3 @@ client.head({

describe('HEAD over HTTPS with SSL validation', function() {
describe('HEAD: over HTTPS with SSL validation', function() {
it('should verify succesfully the connection', function(done) {

@@ -215,12 +216,10 @@ client.head({

describe('HEAD without url', function() {
describe('HEAD: without url', function() {
it('should throw an error', function(done) {
var throws = function() {
assert.throws(function() {
client.head({}, function(err) {
assert.ifError(err);
});
};
}, TypeError, 'Parameter \'options.url\' must be a string, not undefined');
assert.throws(throws, Error, 'The options object requires an input URL value.');
done();

@@ -230,3 +229,3 @@ });

describe('HEAD with redirect loop', function() {
describe('HEAD: with redirect loop', function() {
it('should detect the condition and pass the error argument to the completion callback', function(done) {

@@ -249,3 +248,3 @@ var url = 'http://127.0.0.1:' + common.options.port + '/redirect-loop';

describe('HEAD with URL fragment', function() {
describe('HEAD: with URL fragment', function() {
it('should not send the URL fragment to the server', function(done) {

@@ -263,3 +262,3 @@ client.head('http://127.0.0.1:' + common.options.port + '/path-reflect#fragment', function(err, res) {

describe('HEAD with noSslVerifier', function() {
describe('HEAD: with noSslVerifier', function() {
it('should not pass an error back due to lack of root CA', function(done) {

@@ -281,10 +280,8 @@ client.head({

describe('HEAD with bad callback', function() {
describe('HEAD: with bad callback', function() {
it('should throw and error', function(done) {
var throws = function() {
assert.throws(function() {
client.head('http://127.0.0.1:' + common.options.port + '/');
};
}, TypeError, 'Parameter \'callback\' must be a function, not undefined');
assert.throws(throws, Error, 'Expecting a function for the callback argument for URL: ' + 'http://127.0.0.1:' + common.options.port + '/');
done();

@@ -294,3 +291,3 @@ });

describe('HEAD with standard user agent', function() {
describe('HEAD: with standard user agent', function() {
it('should pass the standard user-agent header', function(done) {

@@ -309,3 +306,3 @@ client.head('http://127.0.0.1:' + common.options.port + '/user-agent-reflect', function(err, res) {

describe('HEAD with user agent turned off', function() {
describe('HEAD: with user agent turned off', function() {
it('should not pass the user-agent header back', function(done) {

@@ -327,3 +324,3 @@ client.head({

describe('HEAD with timeout', function() {
describe('HEAD: with timeout', function() {
it('should timeout', function(done) {

@@ -342,3 +339,3 @@ client.head({

describe('HEAD with proxy', function() {
describe('HEAD: with proxy', function() {
it('should succeed', function(done) {

@@ -363,3 +360,3 @@ client.head({

describe('HEAD with not modified', function() {
describe('HEAD: with not modified', function() {
it('should return a 304 response', function(done) {

@@ -383,3 +380,3 @@ client.head({

describe('HEAD to not-modified without if-modified-since', function() {
describe('HEAD: to not-modified without if-modified-since', function() {
it('should return a 200 response', function(done) {

@@ -398,3 +395,3 @@ client.head('http://127.0.0.1:' + common.options.port + '/not-modified', function(err, res) {

describe('HEAD to proxy to use-proxy', function() {
describe('HEAD: to proxy to use-proxy', function() {
it('should go through the proxy to the use-proxy actual response', function(done) {

@@ -419,3 +416,3 @@ client.head({

describe('HEAD to use-proxy', function() {
describe('HEAD: to use-proxy', function() {
it('should receive the response via a http-proxy', function(done) {

@@ -437,3 +434,3 @@ client.head({

describe('HEAD to redirect from HTTPS to HTTP', function() {
describe('HEAD: to redirect from HTTPS to HTTP', function() {
it('should redirect without issues', function(done) {

@@ -463,2 +460,2 @@ client.head({

});
});

@@ -20,3 +20,3 @@ 'use strict';

describe('MIME file not found', function() {
describe('MIME: file not found', function() {
it('should pass an error', function(done) {

@@ -35,3 +35,3 @@ magic.detectFile('test/data/foobar', function(err, res) {

var testMimeSniff = function(type, mime) {
describe('MIME mimeSniff ' + type, function() {
describe('MIME: mimeSniff ' + type, function() {
it('should detect the MIME type ' + mime, function(done) {

@@ -48,3 +48,3 @@ client.mimeSniff('http://127.0.0.1:' + common.options.filePort + '/' + type + '.foo', function(err, res) {

describe('MIME validate mimeSniff ' + type, function() {
describe('MIME: validate mimeSniff ' + type, function() {
it('should receive ' + mime + ' as content-type response header', function(done) {

@@ -72,2 +72,2 @@ client.get('http://127.0.0.1:' + common.options.filePort + '/' + type + '.foo', function(err, res) {

});
});
});

@@ -6,7 +6,5 @@ 'use strict';

var client = require('../');
var config = require('../package.json');
var common = require('./common.js');
var util = require('util');
var qs = require('querystring');

@@ -25,3 +23,3 @@ var assert = require('chai').assert;

describe('POST request shorthand', function() {
describe('POST: request shorthand', function() {
it('should pass the arguments as query string into the request body', function(done) {

@@ -42,3 +40,3 @@ client.post('http://127.0.0.1:' + common.options.port + '/post?foo=bar&baz=q u x', function(err, res) {

describe('POST request with application/x-www-form-urlencoded', function() {
describe('POST: request with application/x-www-form-urlencoded', function() {
it('should pass the proper request body as querystring with URL encoding', function(done) {

@@ -70,3 +68,3 @@ client.post({

describe('POST request with multipart/form-data', function() {
describe('POST: request with multipart/form-data', function() {
it('should pass the proper request body', function(done) {

@@ -105,2 +103,2 @@ var form = new client.FormData();

});
});

@@ -6,3 +6,2 @@ 'use strict';

var client = require('../');
var config = require('../package.json');

@@ -26,3 +25,3 @@ var common = require('./common.js');

describe('PUT buffer', function() {
describe('PUT: buffer', function() {
it('should make a succesful PUT request', function(done) {

@@ -45,3 +44,3 @@ client.put({

describe('PUT file', function() {
describe('PUT: file', function() {
it('should make a succesful PUT request', function(done) {

@@ -64,3 +63,3 @@ client.put({

describe('PUT pipe http.IncomingMessage', function() {
describe('PUT: pipe http.IncomingMessage', function() {
it('should make a succesful PUT request', function(done) {

@@ -100,2 +99,2 @@ client.get({

});
});

@@ -26,2 +26,2 @@ #!/usr/bin/env node

});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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