@jsenv/server 12.3.1 → 12.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/server",
3
- "version": "12.3.1",
3
+ "version": "12.3.2",
4
4
  "description": "Write your Node.js server using pure functions",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -23,8 +23,8 @@ export const populateNodeResponse = async (
23
23
  status,
24
24
  statusText,
25
25
  headers,
26
+ onHeadersSent,
26
27
  })
27
- onHeadersSent()
28
28
 
29
29
  if (!body) {
30
30
  onEnd()
@@ -135,31 +135,31 @@ export const populateNodeResponse = async (
135
135
  })
136
136
  }
137
137
 
138
- const writeHead = (responseStream, { status, statusText, headers }) => {
138
+ const writeHead = (
139
+ responseStream,
140
+ { status, statusText, headers, onHeadersSent },
141
+ ) => {
139
142
  const responseIsHttp2ServerResponse =
140
143
  responseStream instanceof Http2ServerResponse
141
144
  const responseIsServerHttp2Stream =
142
145
  responseStream.constructor.name === "ServerHttp2Stream"
143
-
144
146
  let nodeHeaders = headersToNodeHeaders(headers, {
145
147
  // https://github.com/nodejs/node/blob/79296dc2d02c0b9872bbfcbb89148ea036a546d0/lib/internal/http2/compat.js#L112
146
148
  ignoreConnectionHeader:
147
149
  responseIsHttp2ServerResponse || responseIsServerHttp2Stream,
148
150
  })
149
-
151
+ if (statusText === undefined) {
152
+ statusText = statusTextFromStatus(status)
153
+ }
150
154
  if (responseIsServerHttp2Stream) {
151
155
  nodeHeaders = {
152
156
  ...nodeHeaders,
153
157
  ":status": status,
154
158
  }
155
159
  responseStream.respond(nodeHeaders)
160
+ onHeadersSent({ nodeHeaders, status, statusText })
156
161
  return
157
162
  }
158
-
159
- if (statusText === undefined) {
160
- statusText = statusTextFromStatus(status)
161
- }
162
-
163
163
  // nodejs strange signature for writeHead force this
164
164
  // https://nodejs.org/api/http.html#http_response_writehead_statuscode_statusmessage_headers
165
165
  if (
@@ -167,10 +167,11 @@ const writeHead = (responseStream, { status, statusText, headers }) => {
167
167
  responseIsHttp2ServerResponse
168
168
  ) {
169
169
  responseStream.writeHead(status, nodeHeaders)
170
+ onHeadersSent({ nodeHeaders, status, statusText })
170
171
  return
171
172
  }
172
-
173
173
  responseStream.writeHead(status, statusText, nodeHeaders)
174
+ onHeadersSent({ nodeHeaders, status, statusText })
174
175
  }
175
176
 
176
177
  const statusTextFromStatus = (status) =>
@@ -664,12 +664,10 @@ export const startServer = async ({
664
664
  })
665
665
  onRequestHandled(requestNode)
666
666
  },
667
- onHeadersSent: () => {
667
+ onHeadersSent: ({ status, statusText }) => {
668
668
  addRequestLog(requestNode, {
669
669
  type: "info",
670
- value: `${colorizeResponseStatus(responseProperties.status)} ${
671
- responseProperties.statusText
672
- }`,
670
+ value: `${colorizeResponseStatus(status)} ${statusText}`,
673
671
  })
674
672
  },
675
673
  onEnd: () => {