Skip to content
Myr

Upgrade `content-type` (#7234)

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

* Upgrade content-type * Bump type-is * test: add tests for content-type handling in res.send() ---------

authored by Blake Embrey · committed by GitHub · parent a08da78 · Browse files · 3 files+35 added−2 removed
This commit

State

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

Trailers

  • Co-authored-by: Sebastian Beltran <bjohansebas@gmail.com>

Diff stats

3 files+35 added−2 removed

  • tests:+26 added−0 removed
  • other:+9 added−2 removed

3 files+35 added−2 removed

modified:test/res.send.js+26 added
120 unmodified lines
121 .expect('Content-Type', 'text/plain; charset=utf-8')122 .expect(200, 'hey', done);123 })124125 it('should preserve existing parameters when adding charset', function(done){126 var app = express();127128 app.use(function(req, res){129 res.set('Content-Type', 'text/plain; foo=bar').send('hey');130 });131132 request(app)133 .get('/')134 .expect('Content-Type', 'text/plain; foo=bar; charset=utf-8')135 .expect(200, 'hey', done);136 })137138 it('should not throw on a Content-Type that fails to parse', function(done){139 var app = express();140141 app.use(function(req, res){142 res.set('Content-Type', 'text/plain; foo').send('hey');143 });144145 request(app)146 .get('/')147 .expect('Content-Type', 'text/plain; charset=utf-8')148 .expect(200, 'hey', done);149 })150151 it('should keep charset in Content-Type for Buffers', function(done){152 var app = express();153154 app.use(function(req, res){
441 unmodified lines
modified:History.md+7 added
8 unmodified lines
9 ```js10 app.render('index', null, callback); // now works as expected11 ```1213* Upgrade `content-type` to `^2.0.0`, bringing a faster parser (~1.5x quicker `Content-Type` parsing/formatting in `res.send()`) along with a behavior change: `res.send()` now keeps any existing parameters when adding the charset and no longer throws on a `Content-Type` that fails to parse - by [@blakeembrey](https://github.com/blakeembrey) in [#7234](https://github.com/expressjs/express/pull/7234)1415 ```js16 res.set('Content-Type', 'text/plain; foo=bar').send('hey');17 // -> Content-Type: text/plain; foo=bar; charset=utf-818 ```1920## ⚡ Performance2122* Avoid duplicate Content-Type header processing in `res.send()` when sending string responses without an explicit Content-Type header - by [@bjohansebas](https://github.com/bjohansebas) in [#6991](https://github.com/expressjs/express/pull/6991)23
3871 unmodified lines
modified:package.json+2 added-2 removed