Skip to content
Myr

Merge pull request #1100 from coolony/master

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

Make string object behave like string literals with res.send

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parents d033865, 2266855 · Browse files · 2 files+40 added−0 removed
This commit

State

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

Diff stats

2 files+40 added−0 removed

  • tests:+36 added−0 removed
  • other:+4 added−0 removed

2 files+40 added−0 removed

modified:lib/response.js+4 added
68 unmodified lines
69 if (2 == arguments.length) {70 this.statusCode = body;71 body = arguments[1];72 }73 74 // Convert string objects to string literals75 if(body instanceof String)76 body = body.toString();7778 switch (typeof body) {79 // response status80 case 'number':
567 unmodified lines
modified:test/res.send.js+36 added
107 unmodified lines
108 })109 })110 })111 112 describe('.send(StringObj)', function(){113 it('should send as html', function(done){114 var app = express();115116 app.use(function(req, res){117 res.send(new String('<p>hey</p>'));118 });119120 request(app)121 .get('/')122 .end(function(res){123 res.headers.should.have.property('content-type', 'text/html; charset=utf-8');124 res.body.should.equal('<p>hey</p>');125 res.statusCode.should.equal(200);126 done();127 })128 })129 130 it('should not override Content-Type', function(done){131 var app = express();132133 app.use(function(req, res){134 res.set('Content-Type', 'text/plain').send(new String('hey'));135 });136137 request(app)138 .get('/')139 .end(function(res){140 res.headers.should.have.property('content-type', 'text/plain');141 res.body.should.equal('hey');142 res.statusCode.should.equal(200);143 done();144 })145 })146 })147 148 describe('.send(Buffer)', function(){149 it('should send as octet-stream', function(done){150 var app = express();151
105 unmodified lines