Comparing version 1.4.1 to 1.4.2
////////////////////////////////////////// | ||
// Needle -- Node.js HTTP Client | ||
// Written by Tomás Pollak <tomas@forkhq.com> | ||
// (c) 2012-2015 - Fork Ltd. | ||
// (c) 2012-2016 - Fork Ltd. | ||
// MIT Licensed | ||
@@ -66,2 +66,3 @@ ////////////////////////////////////////// | ||
parse_response : 'all', // same as true. valid options: 'json', 'xml' or false/null | ||
proxy : null, | ||
@@ -108,3 +109,3 @@ // headers | ||
return Object.keys(defaults).map(function(el) { | ||
if (defaults[el].constructor == type) | ||
if (defaults[el] !== null && defaults[el].constructor == type) | ||
return el; | ||
@@ -172,4 +173,4 @@ }).filter(function(el) { return el }) | ||
http_opts : {}, // passed later to http.request() directly | ||
proxy : options.proxy, | ||
output : options.output, | ||
proxy : get_option('proxy', defaults.proxy), | ||
parser : get_option('parse_response', defaults.parse_response), | ||
@@ -671,8 +672,9 @@ encoding : options.encoding || (options.multipart ? 'binary' : defaults.encoding) | ||
if (defaults.hasOwnProperty(target_key) && typeof obj[key] != 'undefined') { | ||
var valid_type = defaults[target_key].constructor.name; | ||
if (target_key != 'parse_response' && target_key != 'proxy') { | ||
// ensure type matches the original, except for proxy/parse_response that can be null/bool or string | ||
var valid_type = defaults[target_key].constructor.name; | ||
// 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); | ||
if (obj[key].constructor.name != valid_type) | ||
throw new TypeError('Invalid type for ' + key + ', should be ' + valid_type); | ||
} | ||
defaults[target_key] = obj[key]; | ||
@@ -679,0 +681,0 @@ } |
{ | ||
"name": "needle", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "The leanest and most handsome HTTP client in the Nodelands.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -192,12 +192,11 @@ Needle | ||
Generic request. This not only allows for flexibility, but also lets you perform a GET request with data, in which case will be appended to the request as a query string. | ||
Generic request. This not only allows for flexibility, but also lets you perform a GET request with data, in which case will be appended to the request as a query string, unless you pass a `json: true` option (read below). | ||
```js | ||
var data = { | ||
q : 'a very smart query', | ||
page : 2, | ||
format : 'json' | ||
var params = { | ||
q : 'a very smart query', | ||
page : 2 | ||
} | ||
needle.request('get', 'forum.com/search', data, function(err, resp) { | ||
needle.request('get', 'forum.com/search', params, function(err, resp) { | ||
if (!err && resp.statusCode == 200) | ||
@@ -208,2 +207,10 @@ console.log(resp.body); // here you go, mister. | ||
Now, if you set pass `json: true` among the options, Needle won't set your params as a querystring but instead send a JSON representation of your data through the request's body. | ||
```js | ||
needle.request('get', 'forum.com/search', params, { json: true }, function(err) { | ||
if (resp.statusCode == 200) console.log('It worked!'); | ||
}); | ||
``` | ||
More examples after this short break. | ||
@@ -210,0 +217,0 @@ |
@@ -93,2 +93,18 @@ var helpers = require('./helpers'), | ||
describe('but defaults has been set', function() { | ||
before(function() { | ||
needle.defaults({ proxy: 'foobar' }); | ||
}) | ||
after(function() { | ||
needle.defaults({ proxy: null }); | ||
}) | ||
it('tries to proxy anyway', function(done) { | ||
send_request({}, proxied('foobar', 80, done)) | ||
}) | ||
}) | ||
}) | ||
@@ -95,0 +111,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171199
4114
495