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 2 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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"util",
"utility"
],
"version": "2.79.1",
"version": "2.80.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, pull this out. We manage versions independently from PRs

"author": "Mikeal Rogers <mikeal.rogers@gmail.com>",
"repository": {
"type": "git",
Expand Down
48 changes: 48 additions & 0 deletions 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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • assert that there was no error
  • assert the response code

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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • assert that there was no error
  • assert the response code

t.end()
})
})

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