Skip to content
Browse files

Fix http#req delete method handling. #2

  • Loading branch information...
1 parent 5530e43 commit dcb4c68ddecc95ed4549b10d00fa8ea6081a0bc8 @cliffano committed May 10, 2013
Showing with 23 additions and 2 deletions.
  1. +1 −1 CHANGELOG.md
  2. +9 −1 lib/http.js
  3. +13 −0 test/http.js
View
2 CHANGELOG.md
@@ -1,5 +1,5 @@
### 0.1.7-pre
-*
+* Fix http#req delete method handling
### 0.1.6
* Add http#req no proxy hosts handling, localhost and 127.0.0 will ignore proxy by default
View
10 lib/http.js
@@ -74,7 +74,15 @@ function req(method, url, opts, cb) {
return match;
}
- request[method.toLowerCase()](params, function (err, result) {
+ function _requestMethod(method) {
+ var requestMethod = method.toLowerCase();
+ if (requestMethod === 'delete') {
+ requestMethod = 'del';
+ }
+ return requestMethod;
+ }
+
+ request[_requestMethod(method)](params, function (err, result) {
if (err) {
cb(err);
} else {
View
13 test/http.js
@@ -37,6 +37,19 @@ buster.testCase('http - request', {
done();
});
},
+ 'should aliased http#req delete method into request del method': function (done) {
+ this.stub(process, 'env', {});
+ this.stub(request, 'del', function (params, cb) {
+ assert.equals(params.url, 'http://someurl');
+ cb(null, { statusCode: 200, body: 'somebody' });
+ });
+ function _success(result, cb) {
+ cb(null, result);
+ }
+ http.request('DELETE', 'http://someurl', { handlers: { 200: _success } }, function (err, result) {
+ done();
+ });
+ },
'should handle result based on wildcard status code': function (done) {
this.stub(process, 'env', {});
this.stub(request, 'get', function (params, cb) {

0 comments on commit dcb4c68

Please sign in to comment.
Something went wrong with that request. Please try again.