@superhero/http-server 4.2.0 → 4.2.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.
@@ -21,13 +21,13 @@ export default new class AcceptHeaderUpstreamDispatcher
21
21
  splitHeader = request.headers['accept']?.toLowerCase().split(',') || [],
22
22
  accepts = splitHeader.map(this.#normalize),
23
23
  routes = Object.keys(session.route).filter((key) => key.startsWith('accept.') && session.route[key]),
24
- supports = routes.map((route) => [this.#normalize(route), route])
24
+ supports = routes.map((route) => [ this.#normalize(route), route ])
25
25
 
26
26
  for(let accepted of accepts)
27
27
  {
28
28
  accepted = accepted.split(';')[0].split('*')[0]
29
29
 
30
- for(let [supported, route] in supports)
30
+ for(let [ supported, route ] of supports)
31
31
  {
32
32
  supported = supported.split('*')[0]
33
33
 
@@ -13,16 +13,15 @@ export default new class ContentTypeApplicationJsonHeaderUpstreamDispatcher
13
13
  {
14
14
  try
15
15
  {
16
- request.body = JSON.parse(body)
16
+ request.body = JSON.parse(String(body) || '{}')
17
17
  }
18
18
  catch(reason)
19
19
  {
20
20
  const error = new Error('The body is not a valid JSON string')
21
21
  error.code = 'E_HTTP_SERVER_CONTENT_TYPE_HEADER_APPLICATION_JSON'
22
22
  error.status = 400
23
- error.cause = 'The buffered body could not be parsed as a JSON string'
24
-
25
- session.abortion.abort(error)
23
+ error.cause = reason
24
+ return session.abortion.abort(error)
26
25
  }
27
26
  }
28
27
  }
@@ -19,9 +19,9 @@ export default new class ContentTypeHeaderUpstreamDispatcher
19
19
  const
20
20
  contentType = request.headers['content-type'].toLowerCase().split(';')[0].split('*')[0].trim(),
21
21
  routes = Object.keys(session.route).filter((key) => key.startsWith('content-type.') && session.route[key]),
22
- supports = routes.map((route) => [route.replace('content-type.', '').trim(), route])
22
+ supports = routes.map((route) => [ route.replace('content-type.', '').trim(), route ])
23
23
 
24
- for(let [supported, route] in supports)
24
+ for(let [ supported, route ] of supports)
25
25
  {
26
26
  supported = supported.split('*')[0]
27
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/http-server",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "HTTP(S) server component supporting both HTTP 1.1 and HTTP 2.0",
5
5
  "keywords": [
6
6
  "http server",
@@ -22,7 +22,8 @@
22
22
  "./*/*/*/*/*/*": "./*/*/*/*/*/*.js"
23
23
  },
24
24
  "dependencies": {
25
- "@superhero/router": "^4.1.0"
25
+ "@superhero/router": "^4.1.1",
26
+ "@superhero/deep": "^4.1.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@superhero/config": "^4.1.2",
package/view.js CHANGED
@@ -1,4 +1,5 @@
1
- import { Transform } from 'stream'
1
+ import deepmerge from '@superhero/deep/merge'
2
+ import { Transform } from 'node:stream'
2
3
 
3
4
  /**
4
5
  * A view model is a data model specifically designed for the view layer to
@@ -48,7 +49,7 @@ export default class View
48
49
  Object.defineProperties(this,
49
50
  {
50
51
  // The body property is an object that represents the response body.
51
- body : { enumerable: true, value: {} },
52
+ body : { enumerable: true, value: {}, set: (value) => deepmerge(this.body, value) },
52
53
  // The stream property is a transform stream in object mode that by default encodes objects
53
54
  // as stringified JSON data records according to HTML5 standard Server-Sent Events (SSE).
54
55
  stream : { enumerable: true, configurable: true, get: () => this.#lazyloadStream },