Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience method for HTTP OPTIONS #2541

Merged
merged 3 commits into from Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -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')
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()
})
})