@superhero/http-server 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
export default new class AcceptHeaderUpstreamMiddleware
|
|
5
5
|
{
|
|
6
6
|
#listFormat = new Intl.ListFormat('en', { style:'long', type:'disjunction' })
|
|
7
|
-
#normalize = (route) => route.replace('accept
|
|
7
|
+
#normalize = (route) => route.replace('accept.', '').trim()
|
|
8
8
|
|
|
9
9
|
dispatch(request, session)
|
|
10
10
|
{
|
|
11
11
|
const
|
|
12
12
|
splitHeader = request.headers['accept']?.toLowerCase().split(',') || [],
|
|
13
13
|
accepts = splitHeader.map(this.#normalize),
|
|
14
|
-
routes = Object.keys(session.route).filter((key) => key.startsWith('accept
|
|
14
|
+
routes = Object.keys(session.route).filter((key) => key.startsWith('accept.') && session.route[key]),
|
|
15
15
|
supports = routes.map((route) => [this.#normalize(route), route])
|
|
16
16
|
|
|
17
17
|
for(let accepted of accepts)
|
|
@@ -9,8 +9,8 @@ export default new class ContentTypeHeaderUpstreamMiddleware
|
|
|
9
9
|
{
|
|
10
10
|
const
|
|
11
11
|
contentType = request.headers['content-type']?.toLowerCase().split(';')[0].split('*')[0].trim(),
|
|
12
|
-
routes = Object.keys(session.route).filter((key) => key.startsWith('content-type
|
|
13
|
-
supports = routes.map((route) => [route.replace('content-type
|
|
12
|
+
routes = Object.keys(session.route).filter((key) => key.startsWith('content-type.') && session.route[key]),
|
|
13
|
+
supports = routes.map((route) => [route.replace('content-type.', '').trim(), route])
|
|
14
14
|
|
|
15
15
|
for(let [supported, route] in supports)
|
|
16
16
|
{
|
|
@@ -9,23 +9,23 @@ export default new class MethodUpstreamMiddleware
|
|
|
9
9
|
{
|
|
10
10
|
const
|
|
11
11
|
method = request.method.toLowerCase(),
|
|
12
|
-
dispatcher = session.route['method
|
|
12
|
+
dispatcher = session.route['method.' + method] || session.route['method.*']
|
|
13
13
|
|
|
14
14
|
if(dispatcher)
|
|
15
15
|
{
|
|
16
|
-
const
|
|
16
|
+
const
|
|
17
17
|
dispatchers = Array.isArray(dispatcher) ? dispatcher : [dispatcher],
|
|
18
18
|
uniqueList = dispatchers.filter((item) => false === session.chain.dispatchers.includes(item))
|
|
19
19
|
|
|
20
|
-
// insert the forward routed dispatcher(s) after the current dispatcher in the chain
|
|
20
|
+
// insert the forward routed dispatcher(s) after the current dispatcher in the chain
|
|
21
21
|
// for the dispatcher chain iterator to dispatch it/them next
|
|
22
22
|
session.chain.dispatchers.splice(session.chain.index, 0, ...uniqueList)
|
|
23
23
|
return
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const
|
|
27
|
-
supports = Object.keys(session.route).filter((key) => key.startsWith('method
|
|
28
|
-
allowed = supports.map((supported) => supported.replace('method
|
|
27
|
+
supports = Object.keys(session.route).filter((key) => key.startsWith('method.')),
|
|
28
|
+
allowed = supports.map((supported) => supported.replace('method.', '').toUpperCase()).sort(),
|
|
29
29
|
error = new Error(`The requested resource "${request.url}" does not support method "${request.method}"`)
|
|
30
30
|
|
|
31
31
|
error.code = 'E_HTTP_SERVER_MIDDLEWARE_METHOD_NO_MATCHING_DISPATCHER'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superhero/http-server",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "HTTP(S) server component supporting both HTTP 1.1 and HTTP 2.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"http server",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
|
41
|
-
"url": "https://github.com/superhero/http-server"
|
|
41
|
+
"url": "git+https://github.com/superhero/http-server.git"
|
|
42
42
|
}
|
|
43
43
|
}
|