Skip to content
Myr

feat: Added check to support Uint8Array in response sending (#6285)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Unified usage of ArrayBuffer.isView to comprehend Buffer and removed isView function check Co-authored-by: Wes Todd <wes@wesleytodd.com> Added Uint8Array test with encoding

authored by Alexander Cerutti · committed by Wes Todd · parent af7cd90 · Browse files · 3 files+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • fix: added history.md entry

Diff stats

3 files+15 added−1 removed

  • tests:+13 added−0 removed
  • other:+2 added−1 removed

3 files+15 added−1 removed

modified:lib/response.js+1 added-1 removed
128 unmodified lines
129 case 'number':130 case 'object':131 if (chunk === null) {132 chunk = '';133 } else if (Buffer.isBuffer(chunk)) {133 } else if (ArrayBuffer.isView(chunk)) {134 if (!this.get('Content-Type')) {135 this.type('bin');136 }137 } else {
888 unmodified lines
modified:test/res.send.js+13 added
175 unmodified lines
176 .expect('Content-Type', 'text/plain; charset=utf-8')177 .expect(200, 'hey', done);178 })179180 it('should accept Uint8Array', function(done){181 var app = express();182 app.use(function(req, res){183 const encodedHey = new TextEncoder().encode("hey");184 res.set("Content-Type", "text/plain").send(encodedHey);185 })186187 request(app)188 .get("/")189 .expect("Content-Type", "text/plain; charset=utf-8")190 .expect(200, "hey", done);191 })192193 it('should not override ETag', function (done) {194 var app = express()195196 app.use(function (req, res) {
372 unmodified lines
modified:History.md+1 added
7 unmodified lines
8* perf: use loop for acceptParams9* Replace `methods` dependency with standard library10* refactor: prefix built-in node module imports11* Remove unused `depd` dependency12* Add support for `Uint8Array` in `res.send`13145.0.1 / 2024-10-0815==========16
3831 unmodified lines