response.test.js
This file
Path
test/response.test.js
770 lines · 20.7 KiB · JavaScript
Last changed by
Removed `res.send()` with no args support for 204Tj Holowaychukbefore adoptionb13ec85
History of this fileTake it
The walk stopped after 200 commits: lines older than 99b49d2 point at it.
updated docsTj Holowaychukbefore adoption99b49d2
lines 1–11why, one step back12/**3 * Module dependencies.4 */56var express = require('express')7 , Stream = require('stream').Stream8 , assert = require('assert')9 , should = require('should');1011module.exports = {Merge branch 'feature/res-json'Tj Holowaychukbefore adoption9e4020e
lines 12–50why, one step back12 'test #json()': function(){13 var app = express.createServer()14 , json = 'application/json; charset=utf-8';1516 app.get('/user', function(req, res, next){17 res.json({ name: 'tj' });18 });1920 app.get('/string', function(req, res, next){21 res.json('whoop!');22 });2324 app.get('/error', function(req, res, next){25 res.json('oh noes!', 500);26 });2728 app.get('/headers', function(req, res, next){29 res.json(undefined, { 'X-Foo': 'bar' }, 302);30 });3132 assert.response(app,33 { url: '/error' },34 { body: '"oh noes!"'35 , status: 50036 , headers: { 'Content-Type': json }});3738 assert.response(app,39 { url: '/string' },40 { body: '"whoop!"'41 , headers: {42 'Content-Type': json43 , 'Content-Length': 844 }});4546 assert.response(app,47 { url: '/user' },48 { body: '{"name":"tj"}', headers: { 'Content-Type': json }});49 },50Added chainable res.status(code)Tj Holowaychukbefore adoptionb04be51
lines 51–62why, one step back51 'test #status()': function(){52 var app = express.createServer();5354 app.get('/error', function(req, res, next){55 res.status(500).send('OH NO');56 });5758 assert.response(app,59 { url: '/error' },60 { body: 'OH NO', status: 500 });61 },62updated docsTj Holowaychukbefore adoption99b49d2
lines 63–68why, one step back63 'test #send()': function(){64 var app = express.createServer();65 66 app.get('/html', function(req, res){67 res.send('<p>test</p>', { 'Content-Language': 'en' });68 });more testsTj Holowaychukbefore adoption1c65643
line 69why, one step back69updated docsTj Holowaychukbefore adoption99b49d2
lines 70–84why, one step back70 app.get('/json', function(req, res){71 res.header('X-Foo', 'bar');72 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);73 });74 75 app.get('/text', function(req, res){76 res.header('X-Foo', 'bar');77 res.contentType('txt');78 res.send('wahoo');79 });80 81 app.get('/status', function(req, res){82 res.send(404);83 });84 more testsTj Holowaychukbefore adoption1c65643
lines 85–88why, one step back85 app.get('/status/text', function(req, res){86 res.send('Oh noes!', 404);87 });88 updated docsTj Holowaychukbefore adoption99b49d2
lines 89–96why, one step back89 app.get('/error', function(req, res){90 res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);91 });92 93 app.get('/buffer', function(req, res){94 res.send(new Buffer('wahoo!'));95 });96 Removed `res.send()` with no args support for 204Tj Holowaychukbefore adoptionb13ec85
lines 97–98why, one step back97 app.get('/204', function(req, res, next){98 res.send(204);updated docsTj Holowaychukbefore adoption99b49d2
lines 99–111why, one step back99 });100 101 app.get('/undefined', function(req, res, next){102 res.send(undefined);103 });104105 app.get('/bool', function(req, res, next){106 res.send(true);107 });108109 assert.response(app,110 { url: '/bool' },111 { body: 'true'JSON and JSONP default to UTF-8 in the same way as HTML. Introduces app.set('charset') to set charset default at the application level. Closes #632.Daniel Shawbefore adoption8f054db
line 112why, one step back112 , headers: { 'Content-Type': 'application/json; charset=utf-8' }});updated docsTj Holowaychukbefore adoption99b49d2
lines 113–126why, one step back113114 assert.response(app,115 { url: '/html' },116 { body: '<p>test</p>'117 , headers: {118 'Content-Language': 'en'119 , 'Content-Type': 'text/html; charset=utf-8'120 }});121 122 assert.response(app,123 { url: '/json' },124 { body: '{"foo":"bar"}'125 , status: 201126 , headers: {JSON and JSONP default to UTF-8 in the same way as HTML. Introduces app.set('charset') to set charset default at the application level. Closes #632.Daniel Shawbefore adoption8f054db
line 127why, one step back127 'Content-Type': 'application/json; charset=utf-8'updated docsTj Holowaychukbefore adoption99b49d2
lines 128–137why, one step back128 , 'X-Foo': 'baz'129 }});130 131 assert.response(app,132 { url: '/text' },133 { body: 'wahoo'134 , headers: {135 'Content-Type': 'text/plain'136 , 'X-Foo': 'bar'137 }});more testsTj Holowaychukbefore adoption1c65643
lines 138–142why, one step back138139 assert.response(app,140 { url: '/status/text' },141 { body: 'Oh noes!', status: 404 });142updated docsTj Holowaychukbefore adoption99b49d2
lines 143–166why, one step back143 assert.response(app,144 { url: '/status' },145 { body: 'Not Found'146 , status: 404147 , headers: { 'Content-Type': 'text/plain' }});148 149 assert.response(app,150 { url: '/error' },151 { body: 'Oh shit!'152 , status: 500153 , headers: {154 'Content-Type': 'text/plain; charset=utf-8'155 , 'Content-Length': '8'156 }});157 158 assert.response(app,159 { url: '/buffer' },160 { body: 'wahoo!'161 , headers: {162 'Content-Type': 'application/octet-stream'163 , 'Content-Length': '6'164 }});165 166 assert.response(app,Removed `res.send()` with no args support for 204Tj Holowaychukbefore adoptionb13ec85
line 167why, one step back167 { url: '/204' },updated docsTj Holowaychukbefore adoption99b49d2
lines 168–174why, one step back168 { status: 204 }, function(res){169 assert.equal(undefined, res.headers['content-type']);170 assert.equal(undefined, res.headers['content-length']);171 });172173 assert.response(app,174 { url: '/undefined' },Removed `res.send()` with no args support for 204Tj Holowaychukbefore adoptionb13ec85
line 175why, one step back175 { status: 500 });moved jsonp testsTj Holowaychukbefore adoption87bc265
lines 176–184why, one step back176177 assert.response(app,178 { url: '/json?callback=test' },179 { body: '{"foo":"bar"}'180 , status: 201181 , headers: {182 'Content-Type': 'application/json; charset=utf-8'183 , 'X-Foo': 'baz'184 }});updated docsTj Holowaychukbefore adoption99b49d2
line 185why, one step back185 },moved jsonp testsTj Holowaychukbefore adoption87bc265
lines 186–204why, one step back186187 'test #send() JSONP': function(){188 var app = express.createServer();189190 app.enable('jsonp callback');191192 app.get('/jsonp', function(req, res){193 res.header('X-Foo', 'bar');194 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);195 });196197 assert.response(app,198 { url: '/jsonp?callback=test' },199 { body: 'test({"foo":"bar"});'200 , status: 201201 , headers: {202 'Content-Type': 'text/javascript; charset=utf-8'203 , 'X-Foo': 'baz'204 }});updated docsTj Holowaychukbefore adoption99b49d2
line 205why, one step back205 moved jsonp testsTj Holowaychukbefore adoption87bc265
lines 206–212why, one step back206 assert.response(app,207 { url: '/jsonp?callback=baz' },208 { body: 'baz({"foo":"bar"});'209 , status: 201, headers: {210 'Content-Type': 'text/javascript; charset=utf-8'211 , 'X-Foo': 'baz'212 }});Revert "removed jsonp stripping"Tj Holowaychukbefore adoption60d16ea
lines 213–221why, one step back213 214 assert.response(app,215 { url: '/jsonp?callback=invalid()[]' },216 { body: 'invalid({"foo":"bar"});'217 , status: 201218 , headers: {219 'Content-Type': 'text/javascript; charset=utf-8'220 , 'X-Foo': 'baz'221 }});moved jsonp testsTj Holowaychukbefore adoption87bc265
lines 222–223why, one step back222 },223added failing jsonp tests for res.json()Tj Holowaychukbefore adoptione7f2d22
lines 224–246why, one step back224 'test #json() JSONP': function(){225 var app = express.createServer();226227 app.enable('jsonp callback');228229 app.get('/jsonp', function(req, res){230 res.header('X-Foo', 'bar');231 res.json({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);232 });233234 assert.response(app,235 { url: '/jsonp?callback=test' },236 { body: 'test({"foo":"bar"});'237 , status: 201238 , headers: {239 'Content-Type': 'text/javascript; charset=utf-8'240 , 'X-Foo': 'baz'241 }});242 243 assert.response(app,244 { url: '/jsonp?callback=baz' },245 { body: 'baz({"foo":"bar"});'246 , status: 201, headers: {Revert "removed jsonp stripping"Tj Holowaychukbefore adoption60d16ea
lines 247–255why, one step back247 'Content-Type': 'text/javascript; charset=utf-8'248 , 'X-Foo': 'baz'249 }});250 251 assert.response(app,252 { url: '/jsonp?callback=invalid()[]' },253 { body: 'invalid({"foo":"bar"});'254 , status: 201255 , headers: {added failing jsonp tests for res.json()Tj Holowaychukbefore adoptione7f2d22
lines 256–260why, one step back256 'Content-Type': 'text/javascript; charset=utf-8'257 , 'X-Foo': 'baz'258 }});259 },260updated docsTj Holowaychukbefore adoption99b49d2
lines 261–306why, one step back261 'test #contentType()': function(){262 var app = express.createServer();263 264 app.get('/html', function(req, res){265 res.contentType('index.html');266 res.writeHead(200, res.headers);267 res.end('<p>yay</p>');268 });269 270 app.get('/json', function(req, res, next){271 res.contentType('json');272 res.send('{"foo":"bar"}');273 });274275 app.get('/literal', function(req, res){276 res.contentType('application/json');277 res.send('{"foo":"bar"}')278 });279280 assert.response(app,281 { url: '/literal' },282 { headers: { 'Content-Type': 'application/json' }}); 283 assert.response(app,284 { url: '/html' },285 { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html' }});286 assert.response(app,287 { url: '/json' },288 { headers: { 'Content-Type': 'application/json' }});289 },290 291 'test #attachment()': function(){292 var app = express.createServer();293 294 app.get('/style.css', function(req, res){295 res.attachment();296 res.send('some stylezzz');297 });298299 app.get('/*', function(req, res){300 res.attachment(req.params[0]);301 res.send('whatever');302 });303 304 assert.response(app,305 { url: '/javascripts/jquery.js' },306 { body: 'whatever'auto set Content-Type in res.attachementAaron Heckmannbefore adoptione0bc571
lines 307–308why, one step back307 , headers: { 'Content-Type': 'application/javascript'308 , 'Content-Disposition': 'attachment; filename="jquery.js"' }});updated docsTj Holowaychukbefore adoption99b49d2
lines 309–312why, one step back309310 assert.response(app,311 { url: '/style.css' },312 { body: 'some stylezzz'auto set Content-Type in res.attachementAaron Heckmannbefore adoptione0bc571
lines 313–314why, one step back313 , headers: { 'Content-Type': 'text/html; charset=utf-8'314 , 'Content-Disposition': 'attachment' }});updated docsTj Holowaychukbefore adoption99b49d2
lines 315–643why, one step back315 },316 317 'test #redirect()': function(){318 var app = express.createServer()319 , app2 = express.createServer();320 321 app2.set('home', '/blog');322323 app2.redirect('google', 'http://google.com');324325 app2.redirect('blog', function(req, res){326 return req.params.id327 ? '/user/' + req.params.id + '/blog'328 : null;329 });330 331 app.get('/', function(req, res){332 res.redirect('http://google.com', 301);333 });334 335 app.get('/back', function(req, res){336 res.redirect('back');337 });338 339 app.get('/home', function(req, res){340 res.redirect('home');341 });342 343 app.get('/html', function(req, res){344 res.redirect('http://google.com');345 });346 347 app2.get('/', function(req, res){348 res.redirect('http://google.com', 301);349 });350 351 app2.get('/back', function(req, res){352 res.redirect('back');353 });354 355 app2.get('/home', function(req, res){356 res.redirect('home');357 });358 359 app2.get('/google', function(req, res){360 res.redirect('google');361 });362363 app2.get('/user/:id', function(req, res){364 res.header('X-Foo', 'bar');365 res.redirect('blog');366 });367368 assert.response(app,369 { url: '/html', headers: { Accept: 'text/html,text/plain', Host: 'foo.com' }},370 { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });371372 assert.response(app,373 { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},374 { body: 'Moved Permanently. Redirecting to http://google.com'375 , status: 301, headers: { Location: 'http://google.com' }});376377 assert.response(app,378 { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},379 { body: 'Moved Temporarily. Redirecting to http://foo.com/'380 , status: 302, headers: { Location: 'http://foo.com/', 'Content-Type': 'text/plain' }});381382 assert.response(app,383 { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},384 { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'385 , status: 302, headers: { Location: 'http://foo.com/foo' }});386387 assert.response(app,388 { url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},389 { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'390 , status: 302, headers: { Location: 'http://foo.com/foo' }});391392 assert.response(app,393 { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' } },394 { body: 'Moved Temporarily. Redirecting to http://foo.com/'395 , status: 302, headers: { Location: 'http://foo.com/' }});396397 assert.response(app2,398 { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},399 { body: 'Moved Permanently. Redirecting to http://google.com'400 , status: 301, headers: { Location: 'http://google.com' }});401402 assert.response(app2,403 { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},404 { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'405 , status: 302, headers: { Location: 'http://foo.com/blog' }});406407 assert.response(app2,408 { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' }},409 { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'410 , status: 302, headers: { Location: 'http://foo.com/blog' }});411412 assert.response(app2,413 { url: '/google', headers: { Accept: 'text/plain', Host: 'foo.com' }},414 { body: 'Moved Temporarily. Redirecting to http://google.com'415 , status: 302, headers: { Location: 'http://google.com' }});416417 assert.response(app2,418 { url: '/user/12', headers: { Accept: 'text/plain', Host: 'foo.com' }},419 { body: 'Moved Temporarily. Redirecting to http://foo.com/user/12/blog'420 , status: 302, headers: { Location: 'http://foo.com/user/12/blog', 'X-Foo': 'bar' }});421 },422423 'test #redirect() when mounted': function(){424 var app = express.createServer()425 , blog = express.createServer();426427428 blog.get('/posts', function(req, res){429 res.redirect('/posts/all');430 });431432 blog.get('/posts/all', function(req, res){433 res.send('all blog posts');434 });435436 app.use('/blog', blog);437438 assert.response(app,439 { url: '/blog/posts', headers: { Host: 'foo.com' }},440 { status: 302441 , headers: { Location: 'http://foo.com/blog/posts/all' }});442 },443 444 'test #sendfile()': function(){445 var app = express.createServer();446447 app.get('/*', function(req, res, next){448 var file = req.params[0]449 , path = __dirname + '/fixtures/' + file;450 res.sendfile(path);451 });452 453 app.use(express.errorHandler());454455 assert.response(app,456 { url: '/../express.test.js' },457 { body: 'Forbidden', status: 403 });458459 assert.response(app,460 { url: '/user.json' },461 { body: '{"name":"tj"}'462 , status: 200, headers: { 'Content-Type': 'application/json' }});463464 assert.response(app,465 { url: '/hello.haml' },466 { body: '%p Hello World'467 , status: 200, headers: { 'Content-Type': 'application/octet-stream' }});468469 assert.response(app,470 { url: '/doesNotExist' },471 { body: 'Cannot GET /doesNotExist', status: 404 });472473 assert.response(app,474 { url: '/partials' },475 { body: 'Cannot GET /partials', status: 404 });476477 assert.response(app,478 { url: '/large.json' },479 { status: 200, headers: { 'Content-Type': 'application/json' }});480 },481 482 'test #sendfile(path, callback)': function(beforeExit){483 var app = express.createServer()484 , calls = 0;485 486 app.get('/*', function(req, res, next){487 var file = req.params[0]488 , path = __dirname + '/fixtures/' + file;489 res.sendfile(path, function(err){490 if (err) return res.send('got an error');491 ++calls;492 });493 });494495 assert.response(app,496 { url: '/forum' },497 { body: 'got an error' });498499 assert.response(app,500 { url: '/does-not-exist' },501 { body: 'got an error' });502503 assert.response(app,504 { url: '/large.json' },505 { headers: { 'Accept-Ranges': 'bytes' }});506507 beforeExit(function(){508 calls.should.equal(1);509 });510 },511 512 'test #sendfile(path, options, callback)': function(beforeExit){513 var app = express.createServer()514 , calls = 0;515 516 app.get('/*', function(req, res, next){517 var file = req.params[0]518 , path = __dirname + '/fixtures/' + file;519 res.sendfile(path, { maxAge: 3600000 }, function(err){520 if (err) return res.send('got an error');521 ++calls;522 });523 });524525 assert.response(app,526 { url: '/does-not-exist' },527 { body: 'got an error' });528529 assert.response(app,530 { url: '/large.json' },531 { headers: {532 'Accept-Ranges': 'bytes'533 , 'Cache-Control': 'public, max-age=3600'534 }});535536 beforeExit(function(){537 calls.should.equal(1);538 });539 },540 541 'test #sendfile() Accept-Ranges': function(){542 var app = express.createServer();543 544 app.get('/*', function(req, res, next){545 var file = req.params[0]546 , path = __dirname + '/fixtures/' + file;547 res.sendfile(path);548 });549 550 assert.response(app,551 { url: '/large.json' },552 { headers: { 'Accept-Ranges': 'bytes' }});553 },554 555 'test #sendfile() Range': function(){556 var app = express.createServer();557 558 app.get('/*', function(req, res, next){559 var file = req.params[0]560 , path = __dirname + '/fixtures/' + file;561 res.sendfile(path);562 });563 564 assert.response(app,565 { url: '/large.json', headers: { 'Range': 'bytes=0-499' }},566 { headers: {567 'Content-Type': 'application/json',568 'Content-Range': 'bytes 0-499/2535'569 }, status: 206 });570 },571 572 'test #sendfile() Range invalid syntax': function(){573 var app = express.createServer();574 575 app.get('/*', function(req, res, next){576 var file = req.params[0]577 , path = __dirname + '/fixtures/' + file;578 res.sendfile(path);579 });580 581 assert.response(app,582 { url: '/large.json', headers: { 'Range': 'basdytes=asdf' }},583 { body: 'Requested Range Not Satisfiable', status: 416 });584 },585 586 'test #sendfile() Range invalid range': function(){587 var app = express.createServer();588 589 app.get('/*', function(req, res, next){590 var file = req.params[0]591 , path = __dirname + '/fixtures/' + file;592 res.sendfile(path);593 });594 595 assert.response(app,596 { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},597 { body: 'Requested Range Not Satisfiable', status: 416 });598 },599 600 'test #download()': function(beforeExit){601 var app = express.createServer()602 , calls = 0;603 604 app.get('/json', function(req, res, next){605 var path = __dirname + '/fixtures/user.json';606 res.download(path, 'account.json');607 });608609 app.get('/callback', function(req, res, next){610 res.download(__dirname + '/fixtures/pets.json', function(err){611 ++calls;612 });613 });614615 app.get('/*', function(req, res, next){616 res.download(__dirname + '/fixtures/' + req.params[0]);617 });618619 assert.response(app,620 { url: '/callback' },621 { body: '["tobi", "loki", "jane"]' });622623 assert.response(app,624 { url: '/user.json' },625 { body: '{"name":"tj"}', status: 200, headers: {626 'Content-Type': 'application/json',627 'Content-Disposition': 'attachment; filename="user.json"'628 }});629 630 assert.response(app,631 { url: '/json' },632 { body: '{"name":"tj"}', status: 200, headers: {633 'Content-Type': 'application/json',634 'Content-Length': '13',635 'Content-Disposition': 'attachment; filename="account.json"'636 }});637 638 assert.response(app,639 { url: '/missing' },640 function(res){641 assert.equal(null, res.headers['content-disposition']);642 });643added failing test with spaces in filenameTj Holowaychukbefore adoption0d5a637
lines 644–647why, one step back644 assert.response(app,645 { url: '/some%20random%20text%20file.txt' },646 { body: 'hello' });647updated docsTj Holowaychukbefore adoption99b49d2
lines 648–652why, one step back648 beforeExit(function(){649 calls.should.equal(1);650 });651 },652 Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
line 653why, one step back653 'test #cookie() path default': function(){updated docsTj Holowaychukbefore adoption99b49d2
line 654why, one step back654 var app = express.createServer();Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
lines 655–657why, one step back655656 app.set('home', '/foo');657updated docsTj Holowaychukbefore adoption99b49d2
lines 658–667why, one step back658 app.get('/', function(req, res){659 res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });660 res.cookie('something', 'else');661 res.redirect('/');662 });663664 assert.response(app,665 { url: '/', headers: { Host: 'foo.com' }},666 function(res){667 res.headers['set-cookie']Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
line 668why, one step back668 .should.eql(['rememberme=yes; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/foo']);updated docsTj Holowaychukbefore adoption99b49d2
lines 669–670why, one step back669 });670 },Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
lines 671–672why, one step back671672 'test #cookie() explicit path': function(){updated docsTj Holowaychukbefore adoption99b49d2
line 673why, one step back673 var app = express.createServer();Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
lines 674–690why, one step back674675 app.set('/home', '/foo');676677 app.get('/', function(req, res){678 res.cookie('rememberme', 'yes', { path: '/', expires: new Date(1), httpOnly: true });679 res.cookie('something', 'else');680 res.redirect('/');681 });682683 assert.response(app,684 { url: '/', headers: { Host: 'foo.com' }},685 function(res){686 res.headers['set-cookie']687 .should.eql(['rememberme=yes; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/']);688 });689 },690when cookie path === null dont default itTj Holowaychukbefore adoptionee4471b
lines 691–709why, one step back691 'test #cookie() null path': function(){692 var app = express.createServer();693694 app.set('/home', '/foo');695696 app.get('/', function(req, res){697 res.cookie('rememberme', 'yes', { path: null, expires: new Date(1), httpOnly: true });698 res.cookie('something', 'else', { path: null });699 res.redirect('/');700 });701702 assert.response(app,703 { url: '/', headers: { Host: 'foo.com' }},704 function(res){705 res.headers['set-cookie']706 .should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);707 });708 },709Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
lines 710–718why, one step back710 'test #clearCookie() default path': function(){711 var app = express.createServer();712713 app.set('home', '/foo');714715 app.get('/', function(req, res){716 res.clearCookie('rememberme');717 res.redirect('/');718 });updated docsTj Holowaychukbefore adoption99b49d2
line 719why, one step back719 Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
lines 720–732why, one step back720 assert.response(app,721 { url: '/' },722 function(res){723 res.headers['set-cookie']724 .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);725 });726 },727728 'test #clearCookie() explicit path': function(){729 var app = express.createServer();730731 app.set('home', '/bar');732updated docsTj Holowaychukbefore adoption99b49d2
line 733why, one step back733 app.get('/', function(req, res){Added options support to res.clearCookie()Tj Holowaychukbefore adoptiondc02b0d
line 734why, one step back734 res.clearCookie('rememberme', { path: '/foo' });updated docsTj Holowaychukbefore adoption99b49d2
lines 735–741why, one step back735 res.redirect('/');736 });737 738 assert.response(app,739 { url: '/' },740 function(res){741 res.headers['set-cookie']Added options support to res.clearCookie()Tj Holowaychukbefore adoptiondc02b0d
line 742why, one step back742 .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);updated docsTj Holowaychukbefore adoption99b49d2
lines 743–744why, one step back743 });744 },Changed; default cookie path to "home" setting. Closes #731Tj Holowaychukbefore adoption09c9452
line 745why, one step back745updated docsTj Holowaychukbefore adoption99b49d2
lines 746–770why, one step back746 'test HEAD': function(){747 var app = express.createServer();748 749 app.get('/', function(req, res, next){750 res.send('Hello World');751 });752 753 assert.response(app,754 { url: '/', method: 'HEAD' },755 { body: '', headers: { 'Content-Length': 11 }});756 },757 758 'test .charset with res.send()': function(){759 var app = express.createServer();760761 app.get('/', function(req, res){762 res.charset = 'ISO-8859-1';763 res.send('<p>hey</p>');764 });765766 assert.response(app,767 { url: '/' },768 { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});769 }770};