Skip to content

Commit

Permalink
feat(http): support ServerResponse.appendHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 24, 2023
1 parent f50bd51 commit c492d45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/runtime/node/http/_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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<string>
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/node/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -51,6 +53,7 @@ export default <typeof util>{
_errnoException,
_exceptionWithHostPort,
_extend,
aborted,
callbackify,
deprecate,
getSystemErrorMap,
Expand Down

0 comments on commit c492d45

Please sign in to comment.