Skip to content
Myr

res.send.js

This file

Path

test/res.send.js

398 lines · 9.0 KiB · JavaScript

Last changed by

Merge pull request #1889 from vesln/send-null-undefinedJonathan Ongbefore adoption121f8d0

History of this file

Take it

The walk stopped after 200 commits: lines older than 16ba1f6 point at it.

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 1–2why, one step back
1
2var express = require('../')

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

lines 3–4why, one step back
3 , request = require('./support/http')
4 , assert = require('assert');

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 5–16why, one step back
5
6describe('res', function(){7 describe('.send(null)', function(){8 it('should set body to ""', function(done){9 var app = express();1011 app.use(function(req, res){12 res.send(null);13 });1415 request(app)16 .get('/')

Merge pull request #1889 from vesln/send-null-undefinedJonathan Ongbefore adoption121f8d0

line 17why, one step back
17 .expect('Content-Length', '0')

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 18–20why, one step back
18 .expect('', done);
19 })20 })

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

line 21why, one step back
21

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 22–31why, one step back
22 describe('.send(undefined)', function(){
23 it('should set body to ""', function(done){24 var app = express();2526 app.use(function(req, res){27 res.send(undefined);28 });2930 request(app)31 .get('/')

Merge pull request #1889 from vesln/send-null-undefinedJonathan Ongbefore adoption121f8d0

lines 32–35why, one step back
32 .expect('', function(req, res){
33 res.header.should.not.have.property('content-length');34 done();35 });

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 36–52why, one step back
36 })
37 })3839 describe('.send(code)', function(){40 it('should set .statusCode', function(done){41 var app = express();4243 app.use(function(req, res){44 res.send(201).should.equal(res);45 });4647 request(app)48 .get('/')49 .expect('Created')50 .expect(201, done);51 })52 })

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

line 53why, one step back
53

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 54–114why, one step back
54 describe('.send(code, body)', function(){
55 it('should set .statusCode and body', function(done){56 var app = express();5758 app.use(function(req, res){59 res.send(201, 'Created :)');60 });6162 request(app)63 .get('/')64 .expect('Created :)')65 .expect(201, done);66 })67 })6869 describe('.send(body, code)', function(){70 it('should be supported for backwards compat', function(done){71 var app = express();7273 app.use(function(req, res){74 res.send('Bad!', 400);75 });7677 request(app)78 .get('/')79 .expect('Bad!')80 .expect(400, done);81 })82 })8384 describe('.send(String)', function(){85 it('should send as html', function(done){86 var app = express();8788 app.use(function(req, res){89 res.send('<p>hey</p>');90 });9192 request(app)93 .get('/')94 .end(function(err, res){95 res.headers.should.have.property('content-type', 'text/html; charset=utf-8');96 res.text.should.equal('<p>hey</p>');97 res.statusCode.should.equal(200);98 done();99 })100 })101102 it('should set ETag', function(done){103 var app = express();104105 app.use(function(req, res){106 var str = Array(1024 * 2).join('-');107 res.send(str);108 });109110 request(app)111 .get('/')112 .expect('ETag', '"-1498647312"')113 .end(done);114 })

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

lines 115–132why, one step back
115
116 it('should not set ETag for non-GET/HEAD', function(done){117 var app = express();118119 app.use(function(req, res){120 var str = Array(1024 * 2).join('-');121 res.send(str);122 });123124 request(app)125 .post('/')126 .end(function(err, res){127 if (err) return done(err);128 assert(!res.header.etag, 'has an ETag');129 done();130 });131 })132

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 133–146why, one step back
133 it('should not override Content-Type', function(done){
134 var app = express();135136 app.use(function(req, res){137 res.set('Content-Type', 'text/plain').send('hey');138 });139140 request(app)141 .get('/')142 .expect('Content-Type', 'text/plain')143 .expect('hey')144 .expect(200, done);145 })146 })

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

line 147why, one step back
147

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 148–196why, one step back
148 describe('.send(Buffer)', function(){
149 it('should send as octet-stream', function(done){150 var app = express();151152 app.use(function(req, res){153 res.send(new Buffer('hello'));154 });155156 request(app)157 .get('/')158 .end(function(err, res){159 res.headers.should.have.property('content-type', 'application/octet-stream');160 res.text.should.equal('hello');161 res.statusCode.should.equal(200);162 done();163 })164 })165166 it('should set ETag', function(done){167 var app = express();168169 app.use(function(req, res){170 var str = Array(1024 * 2).join('-');171 res.send(new Buffer(str));172 });173174 request(app)175 .get('/')176 .expect('ETag', '"-1498647312"')177 .end(done);178 })179180 it('should not override Content-Type', function(done){181 var app = express();182183 app.use(function(req, res){184 res.set('Content-Type', 'text/plain').send(new Buffer('hey'));185 });186187 request(app)188 .get('/')189 .end(function(err, res){190 res.headers.should.have.property('content-type', 'text/plain');191 res.text.should.equal('hey');192 res.statusCode.should.equal(200);193 done();194 })195 })196 })

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

line 197why, one step back
197

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 198–208why, one step back
198 describe('.send(Object)', function(){
199 it('should send as application/json', function(done){200 var app = express();201202 app.use(function(req, res){203 res.send({ name: 'tobi' });204 });205206 request(app)207 .get('/')208 .end(function(err, res){

Revert "remove charset from json responses. Closes #1631"TJ Holowaychukbefore adoption6cf6c8b

line 209why, one step back
209 res.headers.should.have.property('content-type', 'application/json; charset=utf-8');

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 210–248why, one step back
210 res.text.should.equal('{"name":"tobi"}');
211 done();212 })213 })214 })215216 describe('when the request method is HEAD', function(){217 it('should ignore the body', function(done){218 var app = express();219220 app.use(function(req, res){221 res.send('yay');222 });223224 request(app)225 .head('/')226 .expect('', done);227 })228 })229230 describe('when .statusCode is 204', function(){231 it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){232 var app = express();233234 app.use(function(req, res){235 res.status(204).set('Transfer-Encoding', 'chunked').send('foo');236 });237238 request(app)239 .get('/')240 .end(function(err, res){241 res.headers.should.not.have.property('content-type');242 res.headers.should.not.have.property('content-length');243 res.headers.should.not.have.property('transfer-encoding');244 res.text.should.equal('');245 done();246 })247 })248 })

change generation of ETags with res.send() to GET requests only. Closes #1619TJ Holowaychukbefore adoption3296ed9

line 249why, one step back
249

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

lines 250–324why, one step back
250 describe('when .statusCode is 304', function(){
251 it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){252 var app = express();253254 app.use(function(req, res){255 res.status(304).set('Transfer-Encoding', 'chunked').send('foo');256 });257258 request(app)259 .get('/')260 .end(function(err, res){261 res.headers.should.not.have.property('content-type');262 res.headers.should.not.have.property('content-length');263 res.headers.should.not.have.property('transfer-encoding');264 res.text.should.equal('');265 done();266 })267 })268 })269270 it('should always check regardless of length', function(done){271 var app = express();272273 app.use(function(req, res, next){274 res.set('ETag', 'asdf');275 res.send('hey');276 });277278 request(app)279 .get('/')280 .set('If-None-Match', 'asdf')281 .expect(304, done);282 })283284 it('should respond with 304 Not Modified when fresh', function(done){285 var app = express();286287 app.use(function(req, res){288 var str = Array(1024 * 2).join('-');289 res.send(str);290 });291292 request(app)293 .get('/')294 .set('If-None-Match', '"-1498647312"')295 .expect(304, done);296 })297298 it('should not perform freshness check unless 2xx or 304', function(done){299 var app = express();300301 app.use(function(req, res, next){302 res.status(500);303 res.set('ETag', 'asdf');304 res.send('hey');305 });306307 request(app)308 .get('/')309 .set('If-None-Match', 'asdf')310 .expect('hey')311 .expect(500, done);312 })313314 it('should not support jsonp callbacks', function(done){315 var app = express();316317 app.use(function(req, res){318 res.send({ foo: 'bar' });319 });320321 request(app)322 .get('/?callback=foo')323 .expect('{"foo":"bar"}', done);324 })

Merge pull request #1694 from kavu/add_disable_etagTJ Holowaychukbefore adoption610e172

lines 325–327why, one step back
325
326 describe('"etag" setting', function(){327 describe('when enabled', function(){

always send ETag when content-length > 0Jonathan Ongbefore adoption55d1a4f

lines 328–342why, one step back
328 it('should send ETag even when content-length < 1024', function(done){
329 var app = express();330331 app.use(function(req, res){332 res.send('kajdslfkasdf');333 });334335 request(app)336 .get('/')337 .end(function(err, res){338 res.headers.should.have.property('etag');339 done();340 });341 })342

Merge pull request #1694 from kavu/add_disable_etagTJ Holowaychukbefore adoption610e172

lines 343–397why, one step back
343 it('should send ETag ', function(done){
344 var app = express();345346 app.use(function(req, res){347 var str = Array(1024 * 2).join('-');348 res.send(str);349 });350351 request(app)352 .get('/')353 .end(function(err, res){354 res.headers.should.have.property('etag', '"-1498647312"');355 done();356 });357 });358 });359360 describe('when disabled', function(){361 it('should send no ETag', function(done){362 var app = express();363364 app.use(function(req, res){365 var str = Array(1024 * 2).join('-');366 res.send(str);367 });368369 app.disable('etag');370371 request(app)372 .get('/')373 .end(function(err, res){374 res.headers.should.not.have.property('etag');375 done();376 });377 });378379 it('should send ETag when manually set', function(done){380 var app = express();381382 app.disable('etag');383384 app.use(function(req, res){385 res.set('etag', 1);386 res.send(200);387 });388389 request(app)390 .get('/')391 .end(function(err, res){392 res.headers.should.have.property('etag');393 done();394 });395 });396 });397 })

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption16ba1f6

line 398why, one step back
398})