Skip to content

Commit

Permalink
fix: Do not response Content-Length if Transfer-Encoding is defined (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse authored Oct 19, 2021
1 parent 03643c5 commit dbc9c5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions __tests__/response/length.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,18 @@ describe('res.length', () => {
});
});
});

describe('res.length=', () => {
it('should set when Transfer-Encoding not present', () => {
const res = response();
res.length = 100;
assert.strictEqual(res.length, 100);
});

it('should not set when Transfer-Encoding present', () => {
const res = response();
res.set('Transfer-Encoding', 'chunked');
res.length = 100;
assert.strictEqual(res.length, undefined);
});
});
4 changes: 3 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ module.exports = {
*/

set length(n) {
this.set('Content-Length', n);
if (!this.has('Transfer-Encoding')) {
this.set('Content-Length', n);
}
},

/**
Expand Down

0 comments on commit dbc9c5a

Please sign in to comment.