Skip to content

Commit

Permalink
Add convenience method for HTTP OPTIONS (#2541)
Browse files Browse the repository at this point in the history
* Add convenience method for HTTP OPTIONS. Tests

* Suggested version no

* Applying code review suggestions
  • Loading branch information
jamesseanwright authored and FredKSchott committed Apr 17, 2017
1 parent 52d6945 commit a765593
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -65,6 +65,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')
Expand Down
52 changes: 52 additions & 0 deletions tests/test-options-convenience-method.js
@@ -0,0 +1,52 @@
'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 (err, res) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(res.headers['x-original-method'], 'OPTIONS')
t.end()
})
})

tape('options(object, function)', function (t) {
request.options({
url: s.url + '/options',
headers: { foo: 'bar' }
}, function (err, res) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(res.headers['x-original-method'], 'OPTIONS')
t.end()
})
})

tape('cleanup', function(t) {
s.destroy(function () {
t.end()
})
})

0 comments on commit a765593

Please sign in to comment.