Skip to content

Commit dbc9c5a

Browse files
authored
fix: Do not response Content-Length if Transfer-Encoding is defined (#1602)
1 parent 03643c5 commit dbc9c5a

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

__tests__/response/length.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,18 @@ describe('res.length', () => {
6464
});
6565
});
6666
});
67+
68+
describe('res.length=', () => {
69+
it('should set when Transfer-Encoding not present', () => {
70+
const res = response();
71+
res.length = 100;
72+
assert.strictEqual(res.length, 100);
73+
});
74+
75+
it('should not set when Transfer-Encoding present', () => {
76+
const res = response();
77+
res.set('Transfer-Encoding', 'chunked');
78+
res.length = 100;
79+
assert.strictEqual(res.length, undefined);
80+
});
81+
});

lib/response.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ module.exports = {
191191
*/
192192

193193
set length(n) {
194-
this.set('Content-Length', n);
194+
if (!this.has('Transfer-Encoding')) {
195+
this.set('Content-Length', n);
196+
}
195197
},
196198

197199
/**

0 commit comments

Comments
 (0)