Skip to content
Myr

res.send.js

This file

Path

test/res.send.js

379 lines · 8.5 KiB · JavaScript

Last changed by

Merge pull request #1694 from kavu/add_disable_etagTJ Holowaychukbefore adoption610e172

History of this file

Take it

The walk stopped after 200 commits: lines older than 75debbe point at it.

update connect depTJ Holowaychukbefore adoption75debbe

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');

update connect depTJ Holowaychukbefore adoption75debbe

lines 5–19why, 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('/')17 .expect('', done);18 })19 })

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

line 20why, one step back
20

update connect depTJ Holowaychukbefore adoption75debbe

lines 21–48why, one step back
21 describe('.send(undefined)', function(){
22 it('should set body to ""', function(done){23 var app = express();2425 app.use(function(req, res){26 res.send(undefined);27 });2829 request(app)30 .get('/')31 .expect('', done);32 })33 })3435 describe('.send(code)', function(){36 it('should set .statusCode', function(done){37 var app = express();3839 app.use(function(req, res){40 res.send(201).should.equal(res);41 });4243 request(app)44 .get('/')45 .expect('Created')46 .expect(201, done);47 })48 })

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

line 49why, one step back
49

update connect depTJ Holowaychukbefore adoption75debbe

lines 50–107why, one step back
50 describe('.send(code, body)', function(){
51 it('should set .statusCode and body', function(done){52 var app = express();5354 app.use(function(req, res){55 res.send(201, 'Created :)');56 });5758 request(app)59 .get('/')60 .expect('Created :)')61 .expect(201, done);62 })63 })6465 describe('.send(body, code)', function(){66 it('should be supported for backwards compat', function(done){67 var app = express();6869 app.use(function(req, res){70 res.send('Bad!', 400);71 });7273 request(app)74 .get('/')75 .expect('Bad!')76 .expect(400, done);77 })78 })7980 describe('.send(String)', function(){81 it('should send as html', function(done){82 var app = express();8384 app.use(function(req, res){85 res.send('<p>hey</p>');86 });8788 request(app)89 .get('/')90 .end(function(err, res){91 res.headers.should.have.property('content-type', 'text/html; charset=utf-8');92 res.text.should.equal('<p>hey</p>');93 res.statusCode.should.equal(200);94 done();95 })96 })9798 it('should set ETag', function(done){99 var app = express();100101 app.use(function(req, res){102 var str = Array(1024 * 2).join('-');103 res.send(str);104 });105106 request(app)107 .get('/')

fix etag quoting. Closes #1310TJ Holowaychukbefore adoptioncdb3e9d

line 108why, one step back
108 .expect('ETag', '"-1498647312"')

update connect depTJ Holowaychukbefore adoption75debbe

lines 109–110why, one step back
109 .end(done);
110 })

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

lines 111–128why, one step back
111
112 it('should not set ETag for non-GET/HEAD', function(done){113 var app = express();114115 app.use(function(req, res){116 var str = Array(1024 * 2).join('-');117 res.send(str);118 });119120 request(app)121 .post('/')122 .end(function(err, res){123 if (err) return done(err);124 assert(!res.header.etag, 'has an ETag');125 done();126 });127 })128

update connect depTJ Holowaychukbefore adoption75debbe

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

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

line 143why, one step back
143

update connect depTJ Holowaychukbefore adoption75debbe

lines 144–171why, one step back
144 describe('.send(Buffer)', function(){
145 it('should send as octet-stream', function(done){146 var app = express();147148 app.use(function(req, res){149 res.send(new Buffer('hello'));150 });151152 request(app)153 .get('/')154 .end(function(err, res){155 res.headers.should.have.property('content-type', 'application/octet-stream');156 res.text.should.equal('hello');157 res.statusCode.should.equal(200);158 done();159 })160 })161162 it('should set ETag', function(done){163 var app = express();164165 app.use(function(req, res){166 var str = Array(1024 * 2).join('-');167 res.send(new Buffer(str));168 });169170 request(app)171 .get('/')

fix etag quoting. Closes #1310TJ Holowaychukbefore adoptioncdb3e9d

line 172why, one step back
172 .expect('ETag', '"-1498647312"')

update connect depTJ Holowaychukbefore adoption75debbe

lines 173–192why, one step back
173 .end(done);
174 })175176 it('should not override Content-Type', function(done){177 var app = express();178179 app.use(function(req, res){180 res.set('Content-Type', 'text/plain').send(new Buffer('hey'));181 });182183 request(app)184 .get('/')185 .end(function(err, res){186 res.headers.should.have.property('content-type', 'text/plain');187 res.text.should.equal('hey');188 res.statusCode.should.equal(200);189 done();190 })191 })192 })

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

line 193why, one step back
193

update connect depTJ Holowaychukbefore adoption75debbe

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

remove charset from json responses. Closes #1631TJ Holowaychukbefore adoption138d74a

line 205why, one step back
205 res.headers.should.have.property('content-type', 'application/json');

update connect depTJ Holowaychukbefore adoption75debbe

lines 206–226why, one step back
206 res.text.should.equal('{"name":"tobi"}');
207 done();208 })209 })210 })211212 describe('when the request method is HEAD', function(){213 it('should ignore the body', function(done){214 var app = express();215216 app.use(function(req, res){217 res.send('yay');218 });219220 request(app)221 .head('/')222 .expect('', done);223 })224 })225226 describe('when .statusCode is 204', function(){

Merge pull request #1451 from aweeks/fix-304-must-not-contain-bodyTJ Holowaychukbefore adoption3c4fd57

line 227why, one step back
227 it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){

update connect depTJ Holowaychukbefore adoption75debbe

lines 228–230why, one step back
228 var app = express();
229230 app.use(function(req, res){

Merge pull request #1451 from aweeks/fix-304-must-not-contain-bodyTJ Holowaychukbefore adoption3c4fd57

line 231why, one step back
231 res.status(204).set('Transfer-Encoding', 'chunked').send('foo');

update connect depTJ Holowaychukbefore adoption75debbe

lines 232–238why, one step back
232 });
233234 request(app)235 .get('/')236 .end(function(err, res){237 res.headers.should.not.have.property('content-type');238 res.headers.should.not.have.property('content-length');

Merge pull request #1451 from aweeks/fix-304-must-not-contain-bodyTJ Holowaychukbefore adoption3c4fd57

line 239why, one step back
239 res.headers.should.not.have.property('transfer-encoding');

update connect depTJ Holowaychukbefore adoption75debbe

lines 240–244why, one step back
240 res.text.should.equal('');
241 done();242 })243 })244 })

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

line 245why, one step back
245

update connect depTJ Holowaychukbefore adoption75debbe

line 246why, one step back
246 describe('when .statusCode is 304', function(){

Merge pull request #1451 from aweeks/fix-304-must-not-contain-bodyTJ Holowaychukbefore adoption3c4fd57

line 247why, one step back
247 it('should strip Content-* fields, Transfer-Encoding field, and body', function(done){

update connect depTJ Holowaychukbefore adoption75debbe

lines 248–250why, one step back
248 var app = express();
249250 app.use(function(req, res){

Merge pull request #1451 from aweeks/fix-304-must-not-contain-bodyTJ Holowaychukbefore adoption3c4fd57

line 251why, one step back
251 res.status(304).set('Transfer-Encoding', 'chunked').send('foo');

update connect depTJ Holowaychukbefore adoption75debbe

lines 252–258why, one step back
252 });
253254 request(app)255 .get('/')256 .end(function(err, res){257 res.headers.should.not.have.property('content-type');258 res.headers.should.not.have.property('content-length');

Merge pull request #1451 from aweeks/fix-304-must-not-contain-bodyTJ Holowaychukbefore adoption3c4fd57

line 259why, one step back
259 res.headers.should.not.have.property('transfer-encoding');

update connect depTJ Holowaychukbefore adoption75debbe

lines 260–289why, one step back
260 res.text.should.equal('');
261 done();262 })263 })264 })265266 it('should always check regardless of length', function(done){267 var app = express();268269 app.use(function(req, res, next){270 res.set('ETag', 'asdf');271 res.send('hey');272 });273274 request(app)275 .get('/')276 .set('If-None-Match', 'asdf')277 .expect(304, done);278 })279280 it('should respond with 304 Not Modified when fresh', function(done){281 var app = express();282283 app.use(function(req, res){284 var str = Array(1024 * 2).join('-');285 res.send(str);286 });287288 request(app)289 .get('/')

fix etag quoting. Closes #1310TJ Holowaychukbefore adoptioncdb3e9d

line 290why, one step back
290 .set('If-None-Match', '"-1498647312"')

update connect depTJ Holowaychukbefore adoption75debbe

lines 291–308why, one step back
291 .expect(304, done);
292 })293294 it('should not perform freshness check unless 2xx or 304', function(done){295 var app = express();296297 app.use(function(req, res, next){298 res.status(500);299 res.set('ETag', 'asdf');300 res.send('hey');301 });302303 request(app)304 .get('/')305 .set('If-None-Match', 'asdf')306 .expect('hey')307 .expect(500, done);308 })

add res.jsonp(). Closes #1307TJ Holowaychukbefore adoptiona6caa26

lines 309–320why, one step back
309
310 it('should not support jsonp callbacks', function(done){311 var app = express();312313 app.use(function(req, res){314 res.send({ foo: 'bar' });315 });316317 request(app)318 .get('/?callback=foo')319 .expect('{"foo":"bar"}', done);320 })

Merge pull request #1694 from kavu/add_disable_etagTJ Holowaychukbefore adoption610e172

lines 321–378why, one step back
321
322 describe('"etag" setting', function(){323 describe('when enabled', function(){324 it('should send ETag ', function(done){325 var app = express();326327 app.use(function(req, res){328 var str = Array(1024 * 2).join('-');329 res.send(str);330 });331332 request(app)333 .get('/')334 .end(function(err, res){335 res.headers.should.have.property('etag', '"-1498647312"');336 done();337 });338 });339 });340341 describe('when disabled', function(){342 it('should send no ETag', function(done){343 var app = express();344345 app.use(function(req, res){346 var str = Array(1024 * 2).join('-');347 res.send(str);348 });349350 app.disable('etag');351352 request(app)353 .get('/')354 .end(function(err, res){355 res.headers.should.not.have.property('etag');356 done();357 });358 });359360 it('should send ETag when manually set', function(done){361 var app = express();362363 app.disable('etag');364365 app.use(function(req, res){366 res.set('etag', 1);367 res.send(200);368 });369370 request(app)371 .get('/')372 .end(function(err, res){373 res.headers.should.have.property('etag');374 done();375 });376 });377 });378 })

update connect depTJ Holowaychukbefore adoption75debbe

line 379why, one step back
379})