Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: update method matching (#5419)
* update method matching implementation * push back string comparison * extract encoding * add missing method test * check for transferEncoding as well * skip instead of removing test * Update test/delete.test.js Co-authored-by: Manuel Spigolon <behemoth89@gmail.com> Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day> * Update test/method-missing.test.js Co-authored-by: Manuel Spigolon <behemoth89@gmail.com> Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day> --------- Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day> Co-authored-by: Manuel Spigolon <behemoth89@gmail.com>
- Loading branch information
Showing
5 changed files
with
94 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
'use strict' | ||
|
||
const bodylessMethods = new Set([ | ||
// Standard | ||
'GET', | ||
'HEAD', | ||
'TRACE', | ||
|
||
// WebDAV | ||
'UNLOCK' | ||
]) | ||
|
||
const bodyMethods = new Set([ | ||
// Standard | ||
'DELETE', | ||
'OPTIONS', | ||
'PATCH', | ||
'PUT', | ||
'POST', | ||
|
||
// WebDAV | ||
'COPY', | ||
'LOCK', | ||
'MOVE', | ||
'MKCOL', | ||
'PROPFIND', | ||
'PROPPATCH', | ||
'SEARCH' | ||
]) | ||
|
||
module.exports = { | ||
bodylessMethods, | ||
bodyMethods, | ||
supportedMethods: [ | ||
'DELETE', | ||
'GET', | ||
'HEAD', | ||
'PATCH', | ||
'POST', | ||
'PUT', | ||
'OPTIONS', | ||
'PROPFIND', | ||
'PROPPATCH', | ||
'MKCOL', | ||
'COPY', | ||
'MOVE', | ||
'LOCK', | ||
'UNLOCK', | ||
'TRACE', | ||
'SEARCH' | ||
...bodylessMethods, | ||
...bodyMethods | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const http = require('http') | ||
const { test } = require('tap') | ||
const Fastify = require('../fastify') | ||
|
||
test('missing method from http client', t => { | ||
t.plan(2) | ||
const fastify = Fastify() | ||
|
||
fastify.listen({ port: 3000 }, (err) => { | ||
t.error(err) | ||
|
||
const port = fastify.server.address().port | ||
const req = http.request({ | ||
port, | ||
method: 'REBIND', | ||
path: '/' | ||
}, (res) => { | ||
t.equal(res.statusCode, 404) | ||
fastify.close() | ||
}) | ||
|
||
req.end() | ||
}) | ||
}) |