diff --git a/lib/addMethod/addMethodREST.js b/lib/addMethod/addMethodREST.js index 27987a0..7739076 100644 --- a/lib/addMethod/addMethodREST.js +++ b/lib/addMethod/addMethodREST.js @@ -225,6 +225,9 @@ module.exports = function (methodName, config, afterHeadersFunction) { case 'head': needle[method](request.url, request.options, handleResponse); break; + case 'options': + needle.request('options', request.url, request.options, handleResponse); + break; default: needle[method](request.url, request.data, request.options, handleResponse); } diff --git a/lib/addMethod/validateRESTInput.js b/lib/addMethod/validateRESTInput.js index 1471928..2fbd260 100644 --- a/lib/addMethod/validateRESTInput.js +++ b/lib/addMethod/validateRESTInput.js @@ -32,7 +32,7 @@ module.exports = function (methodName, config) { if (_.isString(method)) { if (!identifySimpleMustache(method)) { method = method.toLowerCase(); - const allowedMethods = [ 'get', 'put', 'post', 'delete', 'head', 'patch' ]; + const allowedMethods = [ 'get', 'put', 'post', 'delete', 'head', 'patch', 'options' ]; if (allowedMethods.indexOf(method) === -1) { throw new Error('The `method` "'+method+'" is not a valid method. Allowed methods are: '+allowedMethods.join(', ')); } diff --git a/tests/addMethodREST_test.js b/tests/addMethodREST_test.js index 56c3787..0597b97 100644 --- a/tests/addMethodREST_test.js +++ b/tests/addMethodREST_test.js @@ -69,7 +69,7 @@ describe('#addMethodREST', function () { method: 'chris' }); } catch (err) { - assert.strictEqual(err.message, 'The `method` "chris" is not a valid method. Allowed methods are: get, put, post, delete, head, patch'); + assert.strictEqual(err.message, 'The `method` "chris" is not a valid method. Allowed methods are: get, put, post, delete, head, patch, options'); caught++; } assert.strictEqual(caught, 1);