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

needle

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

needle - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

img.gif

42

lib/auth.js

@@ -35,9 +35,10 @@ var createHash = require('crypto').createHash;

var challenge = {},
matches = header.match(/([a-z0-9_-]+)="([^"]+)"/gi);
matches = header.match(/([a-z0-9_-]+)="?([a-z0-9=\/\.@\s-]+)"?/gi);
for (var i = 0, l = matches.length; i < l; i++) {
var pos = matches[i].indexOf('='),
key = matches[i].substring(0, pos),
val = matches[i].substring(pos + 1);
challenge[key] = val.substring(1, val.length - 1);
var parts = matches[i].split('='),
key = parts.shift(),
val = parts.join('=').replace(/^"/, '').replace(/"$/, '');
challenge[key] = val;
}

@@ -66,10 +67,10 @@

var ha1 = md5(user + ':' + challenge.realm + ':' + pass),
ha2 = md5(method + ':' + path),
resp = [ha1, challenge.nonce];
var ha1 = md5(user + ':' + challenge.realm + ':' + pass),
ha2 = md5(method.toUpperCase() + ':' + path),
resp = [ha1, challenge.nonce];
if (typeof challenge.qop === 'string') {
cnonce = md5(Math.random().toString(36)).substr(0, 8);
nc = digest.update_nc(nc);
resp = resp.concat(nc, cnonce);
nc = digest.update_nc(nc);
resp = resp.concat(nc, cnonce);
}

@@ -80,14 +81,17 @@

var params = {
username: user,
realm: challenge.realm,
nonce: challenge.nonce,
uri: path,
qop: challenge.qop,
response: md5(resp.join(':'))
uri : path,
realm : challenge.realm,
nonce : challenge.nonce,
username : user,
response : md5(resp.join(':'))
}
// if (challenge.opaque) {
// params.opaque = challenge.opaque;
// }
if (challenge.qop) {
params.qop = challenge.qop;
}
if (challenge.opaque) {
params.opaque = challenge.opaque;
}
if (cnonce) {

@@ -94,0 +98,0 @@ params.nc = nc;

@@ -34,3 +34,3 @@ //

// Parses a set-cookie-string based on the standard definded in RFC6265 S4.1.1.
// Parses a set-cookie-string based on the standard defined in RFC6265 S4.1.1.
function parseSetCookieString(str) {

@@ -37,0 +37,0 @@ str = cleanCookieString(str);

@@ -74,3 +74,3 @@ var readFile = require('fs').readFile,

return_part += '\r\n\r\n';
return_part += part.value;
return_part += new Buffer(String(part.value), 'utf8').toString('binary');
append();

@@ -77,0 +77,0 @@

@@ -59,3 +59,3 @@ //////////////////////////////////////////

encoding : 'utf8',
parse : 'all', // same as true. valid options: 'json', 'xml' or false/null
parse_response : 'all', // same as true. valid options: 'json', 'xml' or false/null

@@ -73,2 +73,3 @@ // headers

decode_response : true,
parse_cookies : true,
follow_set_cookies : false,

@@ -108,3 +109,3 @@ follow_set_referer : false,

function parse_content_type(header) {
if (!header || header == '') return {};
if (!header || header === '') return {};

@@ -131,8 +132,13 @@ var charset = 'iso-8859-1', arr = header.split(';');

this.data = data;
this.options = options;
this.callback = callback;
if (typeof options == 'function') {
this.callback = options;
this.options = {};
} else {
this.callback = callback;
this.options = options;
}
}
Needle.prototype.setup = function(uri, options) {
function get_option(key, fallback) {

@@ -164,3 +170,3 @@ // if original is in options, return that value

output : options.output,
parser : get_option('parse_response', true),
parser : get_option('parse_response', defaults.parse_response),
encoding : options.encoding || (options.multipart ? 'binary' : defaults.encoding)

@@ -190,4 +196,4 @@ }

config.headers = {
'Accept' : options.accept || defaults.accept,
'User-Agent' : options.user_agent || defaults.user_agent
'accept' : options.accept || defaults.accept,
'user-agent' : options.user_agent || defaults.user_agent
}

@@ -197,14 +203,10 @@

if (options.connection || close_by_default)
config.headers['Connection'] = options.connection || 'close';
config.headers['connection'] = options.connection || 'close';
if ((options.compressed || defaults.compressed) && typeof zlib != 'undefined')
config.headers['Accept-Encoding'] = 'gzip,deflate';
config.headers['accept-encoding'] = 'gzip,deflate';
if (options.cookies)
config.headers['Cookie'] = cookies.write(options.cookies);
config.headers['cookie'] = cookies.write(options.cookies);
// now that all our headers are set, overwrite them if instructed.
for (var h in options.headers)
config.headers[h] = options.headers[h];
//////////////////////////////////////////////////

@@ -223,3 +225,3 @@ // basic/digest auth

} else {
config.headers['Authorization'] = auth.basic(options.username, options.password);
config.headers['authorization'] = auth.basic(options.username, options.password);
}

@@ -234,11 +236,15 @@ }

if (config.proxy.indexOf('@') !== -1) {
var parts = (url.parse(config.proxy).auth || '').split(':');
options.proxy_user = parts[0];
options.proxy_pass = parts[1];
var proxy = (url.parse(config.proxy).auth || '').split(':');
options.proxy_user = proxy[0];
options.proxy_pass = proxy[1];
}
if (options.proxy_user)
config.headers['Proxy-Authorization'] = auth.basic(options.proxy_user, options.proxy_pass);
config.headers['proxy-authorization'] = auth.basic(options.proxy_user, options.proxy_pass);
}
// now that all our headers are set, overwrite them if instructed.
for (var h in options.headers)
config.headers[h.toLowerCase()] = options.headers[h];
return config;

@@ -250,3 +256,3 @@ }

var out = new stream.PassThrough({ objectMode: false }),
uri = this.uri,
uri = encodeURI(this.uri),
data = this.data,

@@ -272,4 +278,4 @@ method = this.method,

config.headers['Content-Type'] = 'multipart/form-data; boundary=' + boundary;
config.headers['Content-Length'] = parts.length;
config.headers['content-type'] = 'multipart/form-data; boundary=' + boundary;
config.headers['content-length'] = parts.length;
self.send_request(1, method, uri, config, parts, out, callback);

@@ -304,9 +310,9 @@ });

if (body) {
if (body) {
// unless we have a stream or set a querystring, set the content length.
if (body.length) config.headers['Content-Length'] = body.length;
if (body.length) config.headers['content-length'] = body.length;
// if no content-type was passed, determine if json or not.
if (!config.headers['Content-Type']) {
config.headers['Content-Type'] = options.json
if (!config.headers['content-type']) {
config.headers['content-type'] = options.json
? 'application/json; charset=utf-8'

@@ -317,4 +323,4 @@ : 'application/x-www-form-urlencoded'; // no charset says W3 spec.

// unless a specific accept header was passed, assume json wants json back.
if (options.json && config.headers['Accept'] === defaults.accept)
config.headers['Accept'] = 'application/json';
if (options.json && config.headers['accept'] === defaults.accept)
config.headers['accept'] = 'application/json';
}

@@ -337,10 +343,10 @@

if (!opts.headers['Host']) {
if (!opts.headers['host']) {
// if using proxy, make sure the host header shows the final destination
var target = proxy ? url.parse(uri) : remote;
opts.headers['Host'] = target.hostname;
opts.headers['host'] = target.hostname;
// and if a non standard port was passed, append it to the port header
if (target.port && [80, 443].indexOf(target.port) === -1) {
opts.headers['Host'] += ':' + target.port;
opts.headers['host'] += ':' + target.port;
}

@@ -388,3 +394,2 @@ }

request.removeListener('error', had_error);
request.socket.removeListener('end', on_socket_end);

@@ -408,5 +413,5 @@ if (callback)

// handle errors on the underlying socket, that may be closed while writing
// for an example case, see test/long_string_spec.js. we make sure this
// for an example case, see test/long_string_spec.js. we make sure this
// scenario ocurred by verifying the socket's writable & destroyed states.
function on_socket_end() {
function on_socket_end() {
if (!this.writable && this.destroyed === false) {

@@ -428,3 +433,3 @@ this.destroy();

if (headers['set-cookie']) {
if (headers['set-cookie'] && config.parse_cookies) {
resp.cookies = cookies.read(headers['set-cookie']);

@@ -444,12 +449,12 @@ debug('Got cookies', resp.cookies);

post_data = null;
delete config.headers['Content-Length']; // in case the original was a multipart POST request.
delete config.headers['content-length']; // in case the original was a multipart POST request.
}
if (config.follow_set_cookies && resp.cookies)
config.headers['Cookie'] = cookies.write(resp.cookies);
config.headers['cookie'] = cookies.write(resp.cookies);
if (config.follow_set_referer)
config.headers['Referer'] = uri; // the original, not the destination URL.
config.headers['referer'] = uri; // the original, not the destination URL.
config.headers['Host'] = null; // clear previous Host header to avoid conflicts.
config.headers['host'] = null; // clear previous Host header to avoid conflicts.

@@ -465,7 +470,7 @@ debug('Redirecting to ' + url.resolve(uri, headers.location));

if (resp.statusCode == 401 && headers['www-authenticate'] && config.credentials) {
if (!config.headers['Authorization']) { // only if authentication hasn't been sent
if (!config.headers['authorization']) { // only if authentication hasn't been sent
var auth_header = auth.header(headers['www-authenticate'], config.credentials, request_opts);
if (auth_header) {
config.headers['Authorization'] = auth_header;
config.headers['authorization'] = auth_header;
return self.send_request(count, method, uri, config, post_data, out, callback);

@@ -486,3 +491,8 @@ }

if (headers['content-encoding'] && decompressors[headers['content-encoding']]) {
pipeline.push(decompressors[headers['content-encoding']]());
var decompressor = decompressors[headers['content-encoding']]();
// make sure we catch errors triggered by the decompressor.
decompressor.on('error', had_error);
pipeline.push(decompressor);
}

@@ -532,2 +542,6 @@

out.on('end', function() {
if (file.writable) file.end();
});
out.on('readable', function() {

@@ -612,3 +626,6 @@ var chunk;

request.once('socket', function(socket) {
socket.once('end', on_socket_end.bind(socket));
if (!socket.on_socket_end) {
socket.on_socket_end = on_socket_end;
socket.on('end', socket.on_socket_end);
}
})

@@ -641,6 +658,7 @@

if (defaults.hasOwnProperty(target_key) && typeof obj[key] != 'undefined') {
var valid_type = defaults[target_key].constructor.name;
// ensure type matches the original
if (obj[key].constructor.toString() != defaults[target_key].constructor.toString())
throw new TypeError('Invalid type for ' + key);
// ensure type matches the original, except for parse_response that can be bool or string
if (target_key != 'parse_response' && obj[key].constructor.name != valid_type)
throw new TypeError('Invalid type for ' + key + ', should be ' + valid_type);

@@ -650,2 +668,3 @@ defaults[target_key] = obj[key];

}
return defaults;

@@ -652,0 +671,0 @@ }

{
"name": "needle",
"version": "1.0.0",
"version": "1.1.0",
"description": "The leanest and most handsome HTTP client in the Nodelands.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -220,2 +220,3 @@ Needle

- `output` : Dump response output to file. This occurs after parsing and charset decoding is done.
- `parse_cookies` : Whether to parse response’s `Set-Cookie` header. Defaults to `true`. If parsed, cookies are set on `resp.cookies`.

@@ -234,3 +235,3 @@ Note: To stay light on dependencies, Needle doesn't include the `xml2js` module used for XML parsing. To enable it, simply do `npm install xml2js`.

- `accept` : Sets 'Accept' HTTP header. Defaults to `*/*`.
- `connection`: Sets 'Connection' HTTP header. Defaults to `close`.
- `connection`: Sets 'Connection' HTTP header. Not set by default, unless running Node < 0.11.4 in which case it defaults to `close`. More info about this below.
- `user_agent`: Sets the 'User-Agent' HTTP header. Defaults to `Needle/{version} (Node.js {node_version})`.

@@ -277,2 +278,11 @@

Regarding the 'Connection' header
---------------------------------
Unless you're running an old version of Node (< 0.11.4), by default Needle won't set the Connection header on requests, yielding Node's default behaviour of keeping the connection alive with the target server. This speeds up inmensely the process of sending several requests to the same host.
On older versions, however, this has the unwanted behaviour of preventing the runtime from exiting, either because of a bug or 'feature' that was changed on 0.11.4. To overcome this Needle does set the 'Connection' header to 'close' on those versions, however this also means that making new requests to the same host doesn't benefit from Keep-Alive.
So if you're stuck on 0.10 or even lower and want full speed, you can simply set the Connection header to 'Keep-Alive' by using `{ connection: 'Keep-Alive' }`. Please note, though, that an event loop handler will prevent the runtime from exiting so you'll need to manually call `process.exit()` or the universe will collapse.
Examples Galore

@@ -279,0 +289,0 @@ ---------------

var should = require('should'),
needle = require('./../'),
http = require('http'),
zlib = require('zlib'),
http = require('http'),
zlib = require('zlib'),
stream = require('stream'),
port = 11111,
port = 11111,
server;

@@ -37,3 +37,8 @@

res.setHeader('Content-Type', 'application/json')
raw.end(jsonData)
if (req.headers['with-bad']) {
res.end('foo'); // end, no deflate data
} else {
raw.end(jsonData)
}
}).listen(port);

@@ -77,4 +82,13 @@ });

})
it('should rethrow errors from decompressors', function(done){
needle.get('localhost:' + port, {headers: {'Accept-Encoding': 'deflate', 'With-Bad': 'true'}}, function(err, response, body) {
should.exist(err);
err.message.should.equal("incorrect header check");
err.code.should.equal("Z_DATA_ERROR")
done();
})
})
})
})
})

@@ -128,5 +128,15 @@ var needle = require('../'),

});
describe('with parse_cookies = false', function() {
it('does not parse them', function(done) {
needle.get(
TEST_HOST + ':' + ALL_COOKIES_TEST_PORT, { parse_cookies: false }, function(error, response) {
assert(!response.cookies);
done();
});
});
});
});
describe('if resquest contains cookie header', function() {
describe('if request contains cookie header', function() {
var opts = {

@@ -133,0 +143,0 @@ cookies: {}

@@ -14,3 +14,3 @@ var should = require('should'),

before(function() {
url = 'http://www.huanqiukexue.com/html/newgc/2014/1215/25011.html';
url = 'http://www.nina.jp/server/slackware/webapp/tomcat_charset.html';
})

@@ -25,3 +25,3 @@

chardet.detect(resp.body).encoding.should.eql('windows-1252');
resp.body.indexOf('柳博米尔斯基').should.eql(-1);
resp.body.indexOf('EUCを使う').should.eql(-1);
done();

@@ -41,3 +41,3 @@ })

chardet.detect(resp.body).encoding.should.eql('ascii');
resp.body.indexOf('柳博米尔斯基').should.not.eql(-1);
resp.body.indexOf('EUCを使う').should.not.eql(-1);
done();

@@ -44,0 +44,0 @@ })

@@ -98,2 +98,3 @@ var needle = require('../'),

setTimeout(function() {
should.exist(errorific);
errorific.code.should.match(/ENOTFOUND|EADDRINFO/)

@@ -100,0 +101,0 @@ done();

@@ -25,2 +25,8 @@ var should = require('should'),

// this will only work in UNICES
function get_open_file_descriptors() {
var list = fs.readdirSync('/proc/self/fd');
return list.length;
}
var send_request = send_request_cb;

@@ -107,2 +113,13 @@

it('closes the file descriptor', function(done) {
var open_descriptors = get_open_file_descriptors();
send_request(file + Math.random(), function(err, resp) {
setTimeout(function() {
var current_descriptors = get_open_file_descriptors();
open_descriptors.should.eql(current_descriptors);
done()
}, 10)
})
})
})

@@ -161,2 +178,13 @@

it('closes the file descriptor', function(done) {
var open_descriptors = get_open_file_descriptors();
send_request(file + Math.random(), function(err, resp) {
setTimeout(function() {
var current_descriptors = get_open_file_descriptors();
open_descriptors.should.eql(current_descriptors);
done()
}, 10)
})
})
})

@@ -219,2 +247,13 @@

it('closes the file descriptor', function(done) {
var open_descriptors = get_open_file_descriptors();
send_request(file + Math.random(), function(err, resp) {
setTimeout(function() {
var current_descriptors = get_open_file_descriptors();
open_descriptors.should.eql(current_descriptors);
done()
}, 10)
})
})
})

@@ -221,0 +260,0 @@

@@ -26,10 +26,36 @@ var should = require('should'),

it('should return object', function(done){
needle.get('localhost:' + port, function(err, response, body){
should.ifError(err);
body.should.have.property('foo', 'bar');
done();
describe('with default parse_response', function() {
before(function() {
needle.defaults().parse_response.should.eql('all')
})
it('should return object', function(done){
needle.get('localhost:' + port, function(err, response, body){
should.ifError(err);
body.should.have.property('foo', 'bar');
done();
})
})
})
describe('and default parse_response is set to false', function() {
it('does NOT return object when disabled using .defaults', function(done){
needle.defaults({ parse_response: false })
needle.get('localhost:' + port, function(err, response, body) {
should.not.exist(err);
body.should.be.an.instanceof(Buffer)
body.toString().should.eql('{"foo":"bar"}');
needle.defaults({ parse_response: 'all' });
done();
})
})
})
})

@@ -36,0 +62,0 @@

@@ -11,3 +11,7 @@ var needle = require('..'),

multiparts.push(['\r\nbar\r\n----------------------NODENEEDLEHTTPCLIENT--'])
// multiparts.push(['Content-Disposition: form-data; name=\"test\"'])
// multiparts.push(['\r\næµè¯\r\n----------------------NODENEEDLEHTTPCLIENT--'])
// multiparts.push(['\r\n' + new Buffer('测试').toString() + '\r\n----------------------NODENEEDLEHTTPCLIENT--'])
describe('post data (e.g. request body)', function() {

@@ -49,3 +53,3 @@

stub.calledOnce.should.be.true;
stub.args[0][0]['headers']['Host'].should.equal('localhost:4321');
stub.args[0][0]['headers']['host'].should.equal('localhost:4321');
stub.args[0][0]['method'].should.equal(method);

@@ -100,3 +104,3 @@ }

}).should.throw()
})
})

@@ -112,3 +116,3 @@ })

get({ foo: 'bar' }, { multipart: true }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) {
check_request('get');

@@ -120,3 +124,3 @@ done();

it('sets Content-Type header', function(done) {
post({ foo: 'bar' }, { multipart: true }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) {
resp.body.headers['content-type'].should.equal('multipart/form-data; boundary=--------------------NODENEEDLEHTTPCLIENT');

@@ -128,3 +132,3 @@ done();

it('doesnt change default Accept header', function(done) {
post({ foo: 'bar' }, { multipart: true }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) {
resp.body.headers['accept'].should.equal('*/*');

@@ -148,2 +152,15 @@ done();

it('writes japanese chars correctly as binary', function(done) {
spystub_request();
get({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) {
spy.called.should.be.true;
spy.args[0][0].should.be.a.Buffer;
new Buffer(spy.args[0][0]).toString('hex').should.eql('2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d4e4f44454e4545444c4548545450434c49454e540d0a436f6e74656e742d446973706f736974696f6e3a20666f726d2d646174613b206e616d653d22666f6f220d0a0d0a6261720d0a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d4e4f44454e4545444c4548545450434c49454e540d0a436f6e74656e742d446973706f736974696f6e3a20666f726d2d646174613b206e616d653d2274657374220d0a0d0ac3a6c2b5c28bc3a8c2afc2950d0a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d4e4f44454e4545444c4548545450434c49454e542d2d')
done();
})
})
})

@@ -156,3 +173,3 @@

post({ foo: 'bar' }, { multipart: true }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) {
check_request('post');

@@ -175,2 +192,13 @@ done();

it('writes japanese chars correctly as binary', function(done) {
spystub_request();
post({ foo: 'bar', test: '测试' }, { multipart: true }, function(err, resp) {
spy.called.should.be.true;
spy.args[0][0].should.be.a.Buffer;
new Buffer(spy.args[0][0]).toString('hex').should.eql('2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d4e4f44454e4545444c4548545450434c49454e540d0a436f6e74656e742d446973706f736974696f6e3a20666f726d2d646174613b206e616d653d22666f6f220d0a0d0a6261720d0a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d4e4f44454e4545444c4548545450434c49454e540d0a436f6e74656e742d446973706f736974696f6e3a20666f726d2d646174613b206e616d653d2274657374220d0a0d0ac3a6c2b5c28bc3a8c2afc2950d0a2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d2d4e4f44454e4545444c4548545450434c49454e542d2d')
done();
})
})
})

@@ -464,5 +492,5 @@

get({ foo: 'bar' }, { json: false }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
check_request('get');
stub.args[0][0]['path'].should.equal('/?foo=bar')
stub.args[0][0]['path'].should.equal('/?foo=bar&test=%E6%B5%8B%E8%AF%95')
done();

@@ -473,3 +501,3 @@ })

it('doesnt set Content-Type header', function(done) {
get({ foo: 'bar' }, { json: false }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
// resp.body contains 'header' and 'body', mirroring what we sent

@@ -482,3 +510,3 @@ should.not.exist(resp.body.headers['content-type']);

it('doesnt change default Accept header', function(done) {
get({ foo: 'bar' }, { json: false }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
// resp.body contains 'header' and 'body', mirroring what we sent

@@ -491,3 +519,3 @@ resp.body.headers['accept'].should.equal('*/*');

it('doesnt write anything', function(done) {
get({ foo: 'bar' }, { json: false }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
spy.called.should.be.false;

@@ -506,3 +534,3 @@ resp.body.body.should.eql('');

get({ foo: 'bar' }, { json: true }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
check_request('get');

@@ -515,3 +543,3 @@ stub.args[0][0]['path'].should.equal('/')

it('sets Content-Type header', function(done) {
get({ foo: 'bar' }, { json: true }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
resp.body.headers['content-type'].should.equal('application/json; charset=utf-8');

@@ -523,3 +551,3 @@ done();

it('set Accept header to application/json', function(done) {
get({ foo: 'bar' }, { json: true }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
resp.body.headers['accept'].should.equal('application/json');

@@ -531,5 +559,5 @@ done();

it('writes JSON.stringify version of object', function(done) {
get({ foo: 'bar' }, { json: true }, function(err, resp) {
get({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
spy.called.should.be.true;
var json = JSON.stringify({ foo: 'bar'})
var json = JSON.stringify({ foo: 'bar', test: '测试' })
spy.args[0][0].toString().should.eql(json)

@@ -552,3 +580,3 @@ resp.body.body.should.eql(json);

post({ foo: 'bar' }, { json: false }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
check_request('post');

@@ -560,3 +588,3 @@ done();

it('sets Content-Type header to www-form-urlencoded', function(done) {
post({ foo: 'bar' }, { json: false }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
resp.body.headers['content-type'].should.equal('application/x-www-form-urlencoded');

@@ -568,3 +596,3 @@ done();

it('doesnt change default Accept header', function(done) {
post({ foo: 'bar' }, { json: false }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
// resp.body contains 'header' and 'body', mirroring what we sent

@@ -577,7 +605,7 @@ resp.body.headers['accept'].should.equal('*/*');

it('writes as buffer', function(done) {
post({ foo: 'bar' }, { json: false }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: false }, function(err, resp) {
spy.called.should.be.true;
spy.args[0][0].should.be.a.Buffer;
spy.args[0][0].toString().should.equal('foo=bar');
resp.body.body.should.eql('foo=bar');
spy.args[0][0].toString().should.equal('foo=bar&test=%E6%B5%8B%E8%AF%95');
resp.body.body.should.eql('foo=bar&test=%E6%B5%8B%E8%AF%95');
done();

@@ -594,3 +622,3 @@ })

post({ foo: 'bar' }, { json: true }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
check_request('post');

@@ -602,3 +630,3 @@ done();

it('sets Content-Type header', function(done) {
post({ foo: 'bar' }, { json: true }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
resp.body.headers['content-type'].should.equal('application/json; charset=utf-8');

@@ -610,3 +638,3 @@ done();

it('set Accept header to application/json', function(done) {
post({ foo: 'bar' }, { json: true }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
resp.body.headers['accept'].should.equal('application/json');

@@ -618,5 +646,5 @@ done();

it('writes JSON.stringified object', function(done) {
post({ foo: 'bar' }, { json: true }, function(err, resp) {
post({ foo: 'bar', test: '测试' }, { json: true }, function(err, resp) {
spy.called.should.be.true;
var json = JSON.stringify({ foo: 'bar'})
var json = JSON.stringify({ foo: 'bar', test: '测试' })
spy.args[0][0].toString().should.eql(json)

@@ -623,0 +651,0 @@ resp.body.body.should.eql(json);

@@ -52,3 +52,3 @@ var helpers = require('./helpers'),

var get_auth = function(header) {
function get_auth(header) {
var token = header.split(/\s+/).pop();

@@ -77,7 +77,7 @@ return token && new Buffer(token, 'base64').toString().split(':');

function proxy_auth_set(user, pass, done) {
return header_set('Proxy-Authorization', user, pass, done);
return header_set('proxy-authorization', user, pass, done);
}
function basic_auth_set(user, pass, done) {
return header_set('Authorization', user, pass, done);
return header_set('authorization', user, pass, done);
}

@@ -84,0 +84,0 @@

@@ -286,3 +286,3 @@ var helpers = require('./helpers'),

send_request(opts, function(err, resp) {
spies.http.args[0][0].headers['Referer'].should.eql("http://" + host + ":8888/hello");
spies.http.args[0][0].headers['referer'].should.eql("http://" + host + ":8888/hello");
// spies.http.args[0][3].should.eql({ foo: 'bar'});

@@ -289,0 +289,0 @@ done();

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