Skip to content

Commit

Permalink
Merge pull request #62 from nigrosimone/micro-opt
Browse files Browse the repository at this point in the history
Micro opt
  • Loading branch information
dimdenGD authored Nov 22, 2024
2 parents 20dac39 + 9595188 commit b575e14
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,19 @@ module.exports = class Response extends Writable {
}
writeHeaders(utf8) {
for(const header in this.headers) {
const value = this.headers[header];
if(header === 'content-length') {
// if content-length is set, disable chunked transfer encoding, since size is known
this.chunkedTransfer = false;
this.totalSize = parseInt(this.headers[header]);
this.totalSize = parseInt(value);
continue;
}
if(Array.isArray(this.headers[header])) {
for(let value of this.headers[header]) {
this._res.writeHeader(header, value);
if(Array.isArray(value)) {
for(let val of value) {
this._res.writeHeader(header, val);
}
} else {
this._res.writeHeader(header, this.headers[header]);
this._res.writeHeader(header, value);
}
}
if(!this.headers['content-type']) {
Expand Down Expand Up @@ -306,8 +307,7 @@ module.exports = class Response extends Writable {
// default options
if(typeof options.maxAge === 'string') {
options.maxAge = ms(options.maxAge);
}
if(typeof options.maxAge === 'undefined') {
} else if(typeof options.maxAge === 'undefined') {
options.maxAge = 0;
}
if(typeof options.lastModified === 'undefined') {
Expand Down

0 comments on commit b575e14

Please sign in to comment.