socket-function 1.2.26 → 1.2.27
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 +1 -1
- package/src/callHTTPHandler.ts +12 -3
package/package.json
CHANGED
package/src/callHTTPHandler.ts
CHANGED
|
@@ -13,6 +13,9 @@ import { createSingleton } from "./createSingleton";
|
|
|
13
13
|
// the HTTP handler of any other copy. See createSingleton.
|
|
14
14
|
const defaultHTTPCall = createSingleton("callHTTPHandler.defaultHTTPCall", 1, () => ({ call: undefined as CallType | undefined }));
|
|
15
15
|
|
|
16
|
+
// Statuses where the spec forbids a message body, so we must not write resultBuffer
|
|
17
|
+
const BODYLESS_STATUS_CODES = new Set([204, 205, 304]);
|
|
18
|
+
|
|
16
19
|
export function setDefaultHTTPCall(call: CallType) {
|
|
17
20
|
defaultHTTPCall.get().call = call;
|
|
18
21
|
}
|
|
@@ -253,12 +256,18 @@ export async function httpCallHandler(request: http.IncomingMessage, response: h
|
|
|
253
256
|
|
|
254
257
|
if (headers) {
|
|
255
258
|
for (let headerName in headers) {
|
|
259
|
+
// "status" is the status line, not a header, so don't emit it on the wire
|
|
260
|
+
if (headerName.toLowerCase() === "status") continue;
|
|
256
261
|
response.setHeader(headerName, headers[headerName]);
|
|
257
262
|
}
|
|
258
|
-
let status = headers["status"];
|
|
263
|
+
let status = headers["status"] ?? headers["Status"];
|
|
259
264
|
if (status) {
|
|
260
|
-
|
|
261
|
-
|
|
265
|
+
// Only set statusCode (NOT writeHead), as writeHead locks the header block, which would
|
|
266
|
+
// drop the Content-Type / Content-Length / compression handling below
|
|
267
|
+
response.statusCode = +status;
|
|
268
|
+
if (BODYLESS_STATUS_CODES.has(+status) || +status < 200) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
262
271
|
}
|
|
263
272
|
}
|
|
264
273
|
// With nosniff set, an untyped response is unusable to the browser, so results without explicit headers need their actual type (JSON) declared
|