Skip to content

Commit 08e36cc

Browse files
committed
feat(http): support IncomingMessage.headersDistinct and IncomingMessage.trailersDistinct
1 parent 1eec581 commit 08e36cc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/runtime/node/http/_request.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,24 @@ export class IncomingMessage extends Readable implements http.IncomingMessage {
4141
setTimeout(_msecs: number, _callback?: () => void) {
4242
return this;
4343
}
44+
45+
get headersDistinct() {
46+
return _distinct(this.headers);
47+
}
48+
49+
get trailersDistinct() {
50+
return _distinct(this.trailers);
51+
}
52+
}
53+
54+
function _distinct(obj: Record<string, any>) {
55+
const d: Record<string, string[]> = {};
56+
for (const [key, value] of Object.entries(obj)) {
57+
if (key) {
58+
d[key as string] = (Array.isArray(value) ? value : [value]).filter(
59+
Boolean
60+
);
61+
}
62+
}
63+
return d;
4464
}

0 commit comments

Comments
 (0)