Skip to content

Commit c83cb69

Browse files
authored
Merge pull request #20 from allevo/fix-unknown-method
Only http.METHODS
2 parents fe30245 + f4c8b51 commit c83cb69

File tree

4 files changed

+69
-42
lines changed

4 files changed

+69
-42
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const assert = require('assert')
4+
const http = require('http')
45
const Ajv = require('ajv')
56
const Request = require('./lib/request')
67
const Response = require('./lib/response')
@@ -41,7 +42,7 @@ const schema = {
4142
},
4243
authority: { type: 'string' },
4344
remoteAddress: { type: 'string' },
44-
method: { type: 'string' },
45+
method: { type: 'string', enum: http.METHODS.concat(http.METHODS.map(toLowerCase)) },
4546
validate: { type: 'boolean' }
4647
// payload type => any
4748
},
@@ -83,5 +84,7 @@ function isInjection (obj) {
8384
return (obj instanceof Request || obj instanceof Response)
8485
}
8586

87+
function toLowerCase (m) { return m.toLowerCase() }
88+
8689
module.exports = inject
8790
module.exports.isInjection = isInjection

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"tap": "^11.0.1"
1515
},
1616
"scripts": {
17-
"test": "standard && tap test/test.js"
17+
"test": "npm run lint && npm run unit",
18+
"lint": "standard",
19+
"unit": "tap test/test.js",
20+
"coverage": "npm run unit -- --cov --coverage-report=html"
1821
},
1922
"repository": {
2023
"type": "git",

test/async-await.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function asyncAwaitTest (t, inject) {
1010
}
1111

1212
try {
13-
const res = await inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello' })
13+
const res = await inject(dispatch, { method: 'GET', url: 'http://example.com:8080/hello' })
1414
t.equal(res.payload, 'hello')
1515
} catch (err) {
1616
t.fail(err)
@@ -23,7 +23,7 @@ function asyncAwaitTest (t, inject) {
2323
}
2424

2525
try {
26-
await inject(dispatch, { method: 'get', url: 'http://example.com:8080/hello' })
26+
await inject(dispatch, { method: 'GET', url: 'http://example.com:8080/hello' })
2727
t.fail('should throw')
2828
} catch (err) {
2929
t.ok(err)

0 commit comments

Comments
 (0)