Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Work around a backcompat breakage in Request >=2.9.200.

The URI argument to request() was optional until 2.9.200 and could
be provided in the options object instead, but as of 2.9.200 this
explicitly causes an exception.
  • Loading branch information...
commit b02f3aa0e0e84a76e38f44ce841aa9402b9f8cad 1 parent 86932a7
@rgrove authored
View
6 HISTORY.md
@@ -1,8 +1,10 @@
Elastical History
=================
-0.0.8 (git)
------------
+0.0.8 (2012-04-10)
+------------------
+
+* Added a workaround for API backcompat breakage in Request >= 2.9.200.
* Implemented `Index.count()`. [VirgileD]
View
10 lib/client.js
@@ -152,7 +152,7 @@ Client.prototype = {
@see Index.count
**/
count: wrapStaticIndexMethod('count'),
-
+
/**
Creates a new index.
@@ -702,6 +702,8 @@ Client.prototype = {
@protected
**/
_request: function (path, options, callback) {
+ var url = this.baseUrl + path;
+
if (typeof options === 'function') {
callback = options;
options = {};
@@ -711,7 +713,7 @@ Client.prototype = {
callback || (callback = noop);
options = util.merge(options);
- options.url = this.baseUrl + path;
+ options.uri = url;
options.timeout || (options.timeout = this.options.timeout);
// Write executable curl commands to stderr for easier debugging when
@@ -726,7 +728,7 @@ Client.prototype = {
return this._testHook(null, options), undefined;
}
- request(options, function (err, res, body) {
+ request(url, options, function (err, res, body) {
if (err) { return callback(err), undefined; }
// The request module will automatically try to parse the
@@ -772,7 +774,7 @@ function noop() {}
function curlDebug(options) {
var command = 'curl -X' + (options.method || 'GET');
- command += " '" + options.url + "'";
+ command += " '" + options.uri + "'";
if (options.body) {
command += " --data-binary '" + options.body + "'";
View
2  package.json
@@ -23,7 +23,7 @@
],
"dependencies": {
- "request": "~2.9.3"
+ "request": ">=2.9.3 <=2.9.200"
},
"devDependencies": {
View
78 tests/offline-tests.js
@@ -61,11 +61,11 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_bulk');
+ assert.equal(parseUrl(options.uri).pathname, '/_bulk');
},
'URL should not have a query string': function (err, options) {
- assert.isUndefined(parseUrl(options.url).search);
+ assert.isUndefined(parseUrl(options.uri).search);
},
'body should be formatted correctly': function (err, options) {
@@ -131,7 +131,7 @@ vows.describe('Elastical').addBatch({
},
'URL query string should contain the options': function (err, options) {
- var query = parseUrl(options.url, true).query;
+ var query = parseUrl(options.uri, true).query;
assert.deepEqual({
consistency: 'one',
@@ -153,7 +153,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/new-index');
+ assert.equal(parseUrl(options.uri).pathname, '/new-index');
},
'request should not have a body': function (err, options) {
@@ -188,11 +188,11 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/posts/post/1');
+ assert.equal(parseUrl(options.uri).pathname, '/posts/post/1');
},
'URL should not have a query string': function (err, options) {
- assert.isUndefined(parseUrl(options.url).search);
+ assert.isUndefined(parseUrl(options.uri).search);
}
},
@@ -211,7 +211,7 @@ vows.describe('Elastical').addBatch({
},
'URL query string should contain the options': function (err, options) {
- var query = parseUrl(options.url, true).query;
+ var query = parseUrl(options.uri, true).query;
assert.deepEqual({
consistency: 'all',
@@ -237,7 +237,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo');
+ assert.equal(parseUrl(options.uri).pathname, '/foo');
}
},
@@ -252,7 +252,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo%2Cbar');
+ assert.equal(parseUrl(options.uri).pathname, '/foo%2Cbar');
}
}
},
@@ -269,7 +269,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/_all/1');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/_all/1');
}
},
@@ -287,11 +287,11 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/post/1');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/post/1');
},
'URL query string should contain the options': function (err, options) {
- var query = parseUrl(options.url, true).query;
+ var query = parseUrl(options.uri, true).query;
assert.deepEqual({
fields : 'one,two',
@@ -330,7 +330,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/post');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/post');
},
'request body should be set': function (err, options) {
@@ -366,11 +366,11 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/post/1');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/post/1');
},
'URL query string should contain the options': function (err, options) {
- var query = parseUrl(options.url, true).query;
+ var query = parseUrl(options.uri, true).query;
assert.deepEqual({
consistency : 'all',
@@ -400,7 +400,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo');
+ assert.equal(parseUrl(options.uri).pathname, '/foo');
}
},
@@ -415,7 +415,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo%2Cbar');
+ assert.equal(parseUrl(options.uri).pathname, '/foo%2Cbar');
}
}
},
@@ -432,7 +432,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_all/tweet/_mapping');
+ assert.equal(parseUrl(options.uri).pathname, '/_all/tweet/_mapping');
},
'mapping definition should be passed in the request body': function (err, options) {
@@ -451,7 +451,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo/tweet/_mapping');
+ assert.equal(parseUrl(options.uri).pathname, '/foo/tweet/_mapping');
},
'mapping definition should be passed in the request body': function (err, options) {
@@ -470,7 +470,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo%2Cbar/tweet/_mapping');
+ assert.equal(parseUrl(options.uri).pathname, '/foo%2Cbar/tweet/_mapping');
},
'mapping definition should be passed in the request body': function (err, options) {
@@ -491,7 +491,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_river/my_river_name/_meta');
+ assert.equal(parseUrl(options.uri).pathname, '/_river/my_river_name/_meta');
},
'mapping definition should be passed in the request body': function (err, options) {
@@ -512,7 +512,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_river/my_river_name/_meta');
+ assert.equal(parseUrl(options.uri).pathname, '/_river/my_river_name/_meta');
}
}
},
@@ -529,7 +529,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_river/my_river_name');
+ assert.equal(parseUrl(options.uri).pathname, '/_river/my_river_name');
}
}
},
@@ -546,7 +546,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_all/_refresh');
+ assert.equal(parseUrl(options.uri).pathname, '/_all/_refresh');
}
},
@@ -561,7 +561,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo/_refresh');
+ assert.equal(parseUrl(options.uri).pathname, '/foo/_refresh');
}
},
@@ -576,7 +576,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo%2Cbar/_refresh');
+ assert.equal(parseUrl(options.uri).pathname, '/foo%2Cbar/_refresh');
}
}
},
@@ -598,7 +598,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_search');
+ assert.equal(parseUrl(options.uri).pathname, '/_search');
}
},
@@ -635,11 +635,11 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/post/_search');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/post/_search');
},
'URL query string should contain the correct parameters': function (err, options) {
- var query = parseUrl(options.url, true).query;
+ var query = parseUrl(options.uri, true).query;
assert.deepEqual({
preference : '_primary',
@@ -700,11 +700,11 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/post/_search/scroll');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/post/_search/scroll');
},
'URL query string should contain the correct parameters': function (err, options) {
- var query = parseUrl(options.url, true).query;
+ var query = parseUrl(options.uri, true).query;
assert.deepEqual({
preference : '_primary',
@@ -724,7 +724,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/_search');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/_search');
}
},
@@ -735,7 +735,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_all/post/_search');
+ assert.equal(parseUrl(options.uri).pathname, '/_all/post/_search');
}
},
@@ -749,7 +749,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog%2Ctwitter/post%2Ctweet/_search');
+ assert.equal(parseUrl(options.uri).pathname, '/blog%2Ctwitter/post%2Ctweet/_search');
}
},
@@ -802,7 +802,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_percolator/blog/bar');
+ assert.equal(parseUrl(options.uri).pathname, '/_percolator/blog/bar');
},
'request body should contain the correct options': function (err, options) {
assert.deepEqual(options.json, {
@@ -831,7 +831,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_percolator/blog/bar');
+ assert.equal(parseUrl(options.uri).pathname, '/_percolator/blog/bar');
}
}
},
@@ -851,7 +851,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/blog/bar/_percolate');
+ assert.equal(parseUrl(options.uri).pathname, '/blog/bar/_percolate');
}
}
},
@@ -867,7 +867,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/_percolator/blog/bar');
+ assert.equal(parseUrl(options.uri).pathname, '/_percolator/blog/bar');
}
}
}
@@ -928,7 +928,7 @@ vows.describe('Elastical').addBatch({
},
'URL should have the correct path': function (err, options) {
- assert.equal(parseUrl(options.url).pathname, '/foo/_search');
+ assert.equal(parseUrl(options.uri).pathname, '/foo/_search');
},
'options should be passed through': function (err, options) {
Please sign in to comment.
Something went wrong with that request. Please try again.