http: res.setHeaders first implementation · nodejs/node@5019b54 · GitHub
Skip to content

Commit 5019b54

Browse files
marco-ippolitojuanarbol
authored andcommitted
http: res.setHeaders first implementation
PR-URL: #46109 Backport-PR-URL: #46365 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 3ea53c5 commit 5019b54

3 files changed

Lines changed: 197 additions & 0 deletions

File tree

doc/api/http.md

Lines changed: 44 additions & 0 deletions

lib/_http_outgoing.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,28 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
673673
return this;
674674
};
675675

676+
OutgoingMessage.prototype.setHeaders = function setHeaders(headers) {
677+
if (this._header) {
678+
throw new ERR_HTTP_HEADERS_SENT('set');
679+
}
680+
681+
682+
if (
683+
!headers ||
684+
ArrayIsArray(headers) ||
685+
typeof headers.keys !== 'function' ||
686+
typeof headers.get !== 'function'
687+
) {
688+
throw new ERR_INVALID_ARG_TYPE('headers', ['Headers', 'Map'], headers);
689+
}
690+
691+
for (const key of headers.keys()) {
692+
this.setHeader(key, headers.get(key));
693+
}
694+
695+
return this;
696+
};
697+
676698
OutgoingMessage.prototype.appendHeader = function appendHeader(name, value) {
677699
if (this._header) {
678700
throw new ERR_HTTP_HEADERS_SENT('append');
Lines changed: 131 additions & 0 deletions

0 commit comments

Comments
 (0)