From c492d457afef00ee5e185c9bb4f597f7869a3e9a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 24 May 2023 14:28:48 +0200 Subject: [PATCH] feat(http): support `ServerResponse.appendHeader` --- src/runtime/node/http/_response.ts | 13 +++++++++++++ src/runtime/node/util/index.ts | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/runtime/node/http/_response.ts b/src/runtime/node/http/_response.ts index 65b6b2f2..7b13cea8 100644 --- a/src/runtime/node/http/_response.ts +++ b/src/runtime/node/http/_response.ts @@ -16,8 +16,10 @@ export class ServerResponse extends Writable implements http.ServerResponse { sendDate: boolean = false; finished: boolean = false; headersSent: boolean = false; + strictContentLength = false; connection: Socket | null = null; socket: Socket | null = null; + req: http.IncomingMessage; _headers: HeadersObject = {}; @@ -78,6 +80,17 @@ export class ServerResponse extends Writable implements http.ServerResponse { return this; } + appendHeader(name: string, value: string | string[]) { + name = name.toLowerCase() + const current = this._headers[name]; + const all = [ + ...(Array.isArray(current) ? current : [current]), + ...(Array.isArray(value) ? value : [value]), + ].filter(Boolean) as string[]; + this._headers[name] = all.length > 1 ? all : all[0]; + return this; + } + setHeader( name: string, value: number | string | ReadonlyArray diff --git a/src/runtime/node/util/index.ts b/src/runtime/node/util/index.ts index 99c287b4..d44c82f3 100644 --- a/src/runtime/node/util/index.ts +++ b/src/runtime/node/util/index.ts @@ -28,6 +28,8 @@ export const _exceptionWithHostPort = notImplemented( "util._exceptionWithHostPort" ); export const _extend = notImplemented("util._extend"); + +export const aborted: typeof util.aborted = notImplemented("util.aborted"); export const callbackify: typeof util.callbackify = notImplemented("util.callbackify"); export const getSystemErrorMap: typeof util.getSystemErrorMap = notImplemented( @@ -51,6 +53,7 @@ export default { _errnoException, _exceptionWithHostPort, _extend, + aborted, callbackify, deprecate, getSystemErrorMap,