From d5127a37c833285ed50148af47eb99d967505024 Mon Sep 17 00:00:00 2001 From: James Wright Date: Tue, 14 Feb 2017 12:43:01 +0000 Subject: [PATCH 1/3] Add convenience method for HTTP OPTIONS. Tests --- index.js | 1 + tests/test-options-convenience-method.js | 48 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/test-options-convenience-method.js diff --git a/index.js b/index.js index 9ec65ea26..eac677c70 100755 --- a/index.js +++ b/index.js @@ -66,6 +66,7 @@ function verbFunc (verb) { // define like this to please codeintel/intellisense IDEs request.get = verbFunc('get') request.head = verbFunc('head') +request.options = verbFunc('options') request.post = verbFunc('post') request.put = verbFunc('put') request.patch = verbFunc('patch') diff --git a/tests/test-options-convenience-method.js b/tests/test-options-convenience-method.js new file mode 100644 index 000000000..8c4f99577 --- /dev/null +++ b/tests/test-options-convenience-method.js @@ -0,0 +1,48 @@ +'use strict' + +var server = require('./server') + , request = require('../index') + , tape = require('tape') + , destroyable = require('server-destroy') + +var s = server.createServer() + +destroyable(s) + +tape('setup', function (t) { + s.listen(0, function () { + s.on('/options', function (req, res) { + res.writeHead(200, { + 'x-original-method': req.method, + 'allow': 'OPTIONS, GET, HEAD' + }) + + res.end() + }) + + t.end() + }) +}) + +tape('options(string, function)', function (t) { + request.options(s.url + '/options', function (e, r) { + t.equal(r.headers['x-original-method'], 'OPTIONS') + t.end() + }) +}) + +tape('options(object, function)', function (t) { + request.options({ + url: s.url + '/options', + headers: { foo: 'bar' } + }, function (e, r) { + t.equal(r.headers['x-original-method'], 'OPTIONS') + t.end() + }) +}) + +tape('cleanup', function(t) { + s.destroy(function () { + t.end() + }) +}) \ No newline at end of file From 52e3a4ef3661f4e7670df14d85e6186892f6c36d Mon Sep 17 00:00:00 2001 From: James Wright Date: Tue, 14 Feb 2017 12:45:33 +0000 Subject: [PATCH 2/3] Suggested version no --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 834d0e08c..b209b01e8 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.79.1", + "version": "2.80.0", "author": "Mikeal Rogers ", "repository": { "type": "git", From 3c865943596f0731ad5b9c84529c111dc5432a9c Mon Sep 17 00:00:00 2001 From: James Wright Date: Mon, 20 Feb 2017 18:17:26 +0000 Subject: [PATCH 3/3] Applying code review suggestions --- package.json | 2 +- tests/test-options-convenience-method.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b209b01e8..834d0e08c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "util", "utility" ], - "version": "2.80.0", + "version": "2.79.1", "author": "Mikeal Rogers ", "repository": { "type": "git", diff --git a/tests/test-options-convenience-method.js b/tests/test-options-convenience-method.js index 8c4f99577..a9063b6ef 100644 --- a/tests/test-options-convenience-method.js +++ b/tests/test-options-convenience-method.js @@ -25,8 +25,10 @@ tape('setup', function (t) { }) tape('options(string, function)', function (t) { - request.options(s.url + '/options', function (e, r) { - t.equal(r.headers['x-original-method'], 'OPTIONS') + request.options(s.url + '/options', function (err, res) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(res.headers['x-original-method'], 'OPTIONS') t.end() }) }) @@ -35,8 +37,10 @@ tape('options(object, function)', function (t) { request.options({ url: s.url + '/options', headers: { foo: 'bar' } - }, function (e, r) { - t.equal(r.headers['x-original-method'], 'OPTIONS') + }, function (err, res) { + t.equal(err, null) + t.equal(res.statusCode, 200) + t.equal(res.headers['x-original-method'], 'OPTIONS') t.end() }) })