chainable `res.header()`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent d853f6c · Browse files · 4 files·+778 added−778 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+778 added−778 removed
- tests:+774 added−774 removed
- other:+4 added−4 removed
Provenance
- Commit
41568b7- Tree
bab4b6d- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
d853f6c
4 files changed+778 added−778 removed
modified:lib/router/index.js+1 added-1 removed
264 unmodified lines265 266 Router.prototype._options = function(req, res){267 var path = parse(req.url).pathname268 , body = this._optionsFor(path).join(',');269- res.send(body, { Allow: body });269+ res.header('Allow', body).send(body);270 };271 272 /**273 * Return an array of HTTP verbs or "options" for `path`.111 unmodified linesmodified:lib/response.js+3 added-3 removed
247 unmodified lines248 * Set or get response header `name` with optional `val`.249 *250 * @param {String} name251 * @param {String} val252- * @return {String}252+ * @return {ServerResponse} for chaining253 * @api public254 */255 256 res.header = function(name, val){257- if (val === undefined) {257+ if (1 == arguments.length) {258 return this.getHeader(name);259 } else {260 this.setHeader(name, val);261- return val;261+ return this;262 }263 };264 265 /**139 unmodified linesmodified:test/response.test.js+719 added-719 removed
41 unmodified lines42 assert.response(app,43 { url: '/user' },44 { body: '{"name":"tj"}', headers: { 'Content-Type': json }});45 },46-47- 'test #status()': function(){48- var app = express.createServer();49-50- app.get('/error', function(req, res, next){51- res.status(500).send('OH NO');52- });53-54- assert.response(app,55- { url: '/error' },56- { body: 'OH NO', status: 500 });57- },58-59- 'test #send()': function(){60- var app = express.createServer();61- 62- app.get('/html', function(req, res){63- res.send('<p>test</p>');64- });65-66- app.get('/json', function(req, res){67- res.header('X-Foo', 'bar');68- res.send({ foo: 'bar' }, 201);69- });70- 71- app.get('/text', function(req, res){72- res.header('X-Foo', 'bar');73- res.contentType('txt');74- res.send('wahoo');75- });76- 77- app.get('/status', function(req, res){78- res.send(404);79- });80- 81- app.get('/status/text', function(req, res){82- res.send('Oh noes!', 404);83- });84- 85- app.get('/error', function(req, res){86- res.send('Oh shit!', 500);87- });88- 89- app.get('/buffer', function(req, res){90- res.send(new Buffer('wahoo!'));91- });92- 93- app.get('/204', function(req, res, next){94- res.send(204);95- });96- 97- app.get('/undefined', function(req, res, next){98- res.send(undefined);99- });100-101- app.get('/bool', function(req, res, next){102- res.send(true);103- });104-105- assert.response(app,106- { url: '/bool' },107- { body: 'true'108- , headers: { 'Content-Type': 'application/json; charset=utf-8' }});109-110- assert.response(app,111- { url: '/html' },112- { body: '<p>test</p>'113- , headers: {114- 'Content-Type': 'text/html; charset=utf-8'115- }});116- 117- assert.response(app,118- { url: '/json' },119- { body: '{"foo":"bar"}'120- , status: 201121- , headers: {122- 'Content-Type': 'application/json; charset=utf-8'123- , 'X-Foo': 'baz'124- }});125- 126- assert.response(app,127- { url: '/text' },128- { body: 'wahoo'129- , headers: {130- 'Content-Type': 'text/plain'131- , 'X-Foo': 'bar'132- }});133-134- assert.response(app,135- { url: '/status/text' },136- { body: 'Oh noes!', status: 404 });137-138- assert.response(app,139- { url: '/status' },140- { body: 'Not Found'141- , status: 404142- , headers: { 'Content-Type': 'text/plain' }});143- 144- assert.response(app,145- { url: '/error' },146- { body: 'Oh shit!'147- , status: 500148- , headers: {149- 'Content-Type': 'text/plain; charset=utf-8'150- , 'Content-Length': '8'151- }});152- 153- assert.response(app,154- { url: '/buffer' },155- { body: 'wahoo!'156- , headers: {157- 'Content-Type': 'application/octet-stream'158- , 'Content-Length': '6'159- }});160- 161- assert.response(app,162- { url: '/204' },163- { status: 204 }, function(res){164- assert.equal(undefined, res.headers['content-type']);165- assert.equal(undefined, res.headers['content-length']);166- });167-168- assert.response(app,169- { url: '/undefined' },170- { status: 500 });171-172- assert.response(app,173- { url: '/json?callback=test' },174- { body: '{"foo":"bar"}'175- , status: 201176- , headers: {177- 'Content-Type': 'application/json; charset=utf-8'178- , 'X-Foo': 'baz'179- }});180- },181-182- 'test #send() JSONP': function(){183- var app = express.createServer();184-185- app.enable('jsonp callback');186-187- app.get('/jsonp', function(req, res){188- res.header('X-Foo', 'bar');189- res.send({ foo: 'bar' }, 201);190- });191-192- assert.response(app,193- { url: '/jsonp?callback=test' },194- { body: 'test({"foo":"bar"});'195- , status: 201196- , headers: {197- 'Content-Type': 'text/javascript; charset=utf-8'198- , 'X-Foo': 'bar'199- }});200- 201- assert.response(app,202- { url: '/jsonp?callback=baz' },203- { body: 'baz({"foo":"bar"});'204- , status: 201, headers: {205- 'Content-Type': 'text/javascript; charset=utf-8'206- , 'X-Foo': 'bar'207- }});208- 209- assert.response(app,210- { url: '/jsonp?callback=invalid()[]' },211- { body: 'invalid({"foo":"bar"});'212- , status: 201213- , headers: {214- 'Content-Type': 'text/javascript; charset=utf-8'215- , 'X-Foo': 'bar'216- }});217- },218-219- 'test #json() JSONP': function(){220- var app = express.createServer();221-222- app.enable('jsonp callback');223-224- app.get('/jsonp', function(req, res){225- res.header('X-Foo', 'bar');226- res.json({ foo: 'bar' }, 201);227- });228-229- assert.response(app,230- { url: '/jsonp?callback=test' },231- { body: 'test({"foo":"bar"});'232- , status: 201233- , headers: {234- 'Content-Type': 'text/javascript; charset=utf-8'235- , 'X-Foo': 'bar'236- }});237- 238- assert.response(app,239- { url: '/jsonp?callback=baz' },240- { body: 'baz({"foo":"bar"});'241- , status: 201, headers: {242- 'Content-Type': 'text/javascript; charset=utf-8'243- , 'X-Foo': 'bar'244- }});245- 246- assert.response(app,247- { url: '/jsonp?callback=invalid()[]' },248- { body: 'invalid({"foo":"bar"});'249- , status: 201250- , headers: {251- 'Content-Type': 'text/javascript; charset=utf-8'252- , 'X-Foo': 'bar'253- }});254- },255-256- 'test #contentType()': function(){257- var app = express.createServer();258- 259- app.get('/html', function(req, res){260- res.contentType('index.html');261- res.writeHead(200, res.headers);262- res.end('<p>yay</p>');263- });264- 265- app.get('/json', function(req, res, next){266- res.contentType('json');267- res.send('{"foo":"bar"}');268- });269-270- app.get('/literal', function(req, res){271- res.contentType('application/json');272- res.send('{"foo":"bar"}')273- });274-275- assert.response(app,276- { url: '/literal' },277- { headers: { 'Content-Type': 'application/json' }}); 278- assert.response(app,279- { url: '/html' },280- { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html' }});281- assert.response(app,282- { url: '/json' },283- { headers: { 'Content-Type': 'application/json' }});284- },285- 286- 'test #attachment()': function(){287- var app = express.createServer();288- 289- app.get('/style.css', function(req, res){290- res.attachment();291- res.send('some stylezzz');292- });293-294- app.get('/*', function(req, res){295- res.attachment(req.params[0]);296- res.send('whatever');297- });298- 299- assert.response(app,300- { url: '/javascripts/jquery.js' },301- { body: 'whatever'302- , headers: { 'Content-Type': 'application/javascript'303- , 'Content-Disposition': 'attachment; filename="jquery.js"' }});304-305- assert.response(app,306- { url: '/style.css' },307- { body: 'some stylezzz'308- , headers: { 'Content-Type': 'text/html; charset=utf-8'309- , 'Content-Disposition': 'attachment' }});310- },311- 312- 'test #redirect()': function(){313- var app = express.createServer()314- , app2 = express.createServer();315- 316- app2.set('home', '/blog');317-318- app2.redirect('google', 'http://google.com');319-320- app2.redirect('blog', function(req, res){321- return req.params.id322- ? '/user/' + req.params.id + '/blog'323- : null;324- });325- 326- app.get('/', function(req, res){327- res.redirect('http://google.com', 301);328- });329- 330- app.get('/back', function(req, res){331- res.redirect('back');332- });333- 334- app.get('/home', function(req, res){335- res.redirect('home');336- });337- 338- app.get('/html', function(req, res){339- res.redirect('http://google.com');340- });341- 342- app2.get('/', function(req, res){343- res.redirect('http://google.com', 301);344- });345- 346- app2.get('/back', function(req, res){347- res.redirect('back');348- });349- 350- app2.get('/home', function(req, res){351- res.redirect('home');352- });353- 354- app2.get('/google', function(req, res){355- res.redirect('google');356- });357-358- app2.get('/user/:id', function(req, res){359- res.header('X-Foo', 'bar');360- res.redirect('blog');361- });362-363- assert.response(app,364- { url: '/html', headers: { Accept: 'text/html,text/plain', Host: 'foo.com' }},365- { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });366-367- assert.response(app,368- { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},369- { body: 'Moved Permanently. Redirecting to http://google.com'370- , status: 301, headers: { Location: 'http://google.com' }});371-372- assert.response(app,373- { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},374- { body: 'Moved Temporarily. Redirecting to http://foo.com/'375- , status: 302, headers: { Location: 'http://foo.com/', 'Content-Type': 'text/plain' }});376-377- assert.response(app,378- { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},379- { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'380- , status: 302, headers: { Location: 'http://foo.com/foo' }});381-382- assert.response(app,383- { url: '/back', headers: { Referrer: '/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' }});386-387- assert.response(app,388- { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' } },389- { body: 'Moved Temporarily. Redirecting to http://foo.com/'390- , status: 302, headers: { Location: 'http://foo.com/' }});391-392- assert.response(app2,393- { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},394- { body: 'Moved Permanently. Redirecting to http://google.com'395- , status: 301, headers: { Location: 'http://google.com' }});396-397- assert.response(app2,398- { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},399- { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'400- , status: 302, headers: { Location: 'http://foo.com/blog' }});401-402- assert.response(app2,403- { url: '/home', 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' }});406-407- assert.response(app2,408- { url: '/google', headers: { Accept: 'text/plain', Host: 'foo.com' }},409- { body: 'Moved Temporarily. Redirecting to http://google.com'410- , status: 302, headers: { Location: 'http://google.com' }});411-412- assert.response(app2,413- { url: '/user/12', headers: { Accept: 'text/plain', Host: 'foo.com' }},414- { body: 'Moved Temporarily. Redirecting to http://foo.com/user/12/blog'415- , status: 302, headers: { Location: 'http://foo.com/user/12/blog', 'X-Foo': 'bar' }});416- },417-418- 'test #redirect() when mounted': function(){419- var app = express.createServer()420- , blog = express.createServer();421-422-423- blog.get('/posts', function(req, res){424- res.redirect('/posts/all');425- });426-427- blog.get('/posts/all', function(req, res){428- res.send('all blog posts');429- });430-431- app.use('/blog', blog);432-433- assert.response(app,434- { url: '/blog/posts', headers: { Host: 'foo.com' }},435- { status: 302436- , headers: { Location: 'http://foo.com/blog/posts/all' }});437- },438- 439- 'test #sendfile()': function(){440- var app = express.createServer();441-442- app.get('/*', function(req, res, next){443- var file = req.params[0]444- , path = __dirname + '/fixtures/' + file;445- res.sendfile(path);446- });447- 448- app.use(express.errorHandler());449-450- assert.response(app,451- { url: '/../express.test.js' },452- { body: 'Forbidden', status: 403 });453-454- assert.response(app,455- { url: '/user.json' },456- { body: '{"name":"tj"}'457- , status: 200, headers: { 'Content-Type': 'application/json' }});458-459- assert.response(app,460- { url: '/hello.haml' },461- { body: '%p Hello World'462- , status: 200, headers: { 'Content-Type': 'application/octet-stream' }});463-464- assert.response(app,465- { url: '/doesNotExist' },466- { body: 'Cannot GET /doesNotExist', status: 404 });467-468- assert.response(app,469- { url: '/partials' },470- { body: 'Cannot GET /partials', status: 404 });471-472- assert.response(app,473- { url: '/large.json' },474- { status: 200, headers: { 'Content-Type': 'application/json' }});475- },476- 477- 'test #sendfile(path, callback)': function(beforeExit){478- var app = express.createServer()479- , calls = 0;480- 481- app.get('/*', function(req, res, next){482- var file = req.params[0]483- , path = __dirname + '/fixtures/' + file;484- res.sendfile(path, function(err){485- if (err) return res.send('got an error');486- ++calls;487- });488- });489-490- assert.response(app,491- { url: '/forum' },492- { body: 'got an error' });493-494- assert.response(app,495- { url: '/does-not-exist' },496- { body: 'got an error' });497-498- assert.response(app,499- { url: '/large.json' },500- { headers: { 'Accept-Ranges': 'bytes' }});501-502- beforeExit(function(){503- calls.should.equal(1);504- });505- },506- 507- 'test #sendfile(path, options, callback)': function(beforeExit){508- var app = express.createServer()509- , calls = 0;510- 511- app.get('/*', function(req, res, next){512- var file = req.params[0]513- , path = __dirname + '/fixtures/' + file;514- res.sendfile(path, { maxAge: 3600000 }, function(err){515- if (err) return res.send('got an error');516- ++calls;517- });518- });519-520- assert.response(app,521- { url: '/does-not-exist' },522- { body: 'got an error' });523-524- assert.response(app,525- { url: '/large.json' },526- { headers: {527- 'Accept-Ranges': 'bytes'528- , 'Cache-Control': 'public, max-age=3600'529- }});530-531- beforeExit(function(){532- calls.should.equal(1);533- });534- },535- 536- 'test #sendfile() Accept-Ranges': function(){537- var app = express.createServer();538- 539- app.get('/*', function(req, res, next){540- var file = req.params[0]541- , path = __dirname + '/fixtures/' + file;542- res.sendfile(path);543- });544- 545- assert.response(app,546- { url: '/large.json' },547- { headers: { 'Accept-Ranges': 'bytes' }});548- },549- 550- 'test #sendfile() Range': function(){551- var app = express.createServer();552- 553- app.get('/*', function(req, res, next){554- var file = req.params[0]555- , path = __dirname + '/fixtures/' + file;556- res.sendfile(path);557- });558- 559- assert.response(app,560- { url: '/large.json', headers: { 'Range': 'bytes=0-499' }},561- { headers: {562- 'Content-Type': 'application/json',563- 'Content-Range': 'bytes 0-499/2535'564- }, status: 206 });565- },566- 567- 'test #sendfile() Range invalid syntax': function(){568- var app = express.createServer();569- 570- app.get('/*', function(req, res, next){571- var file = req.params[0]572- , path = __dirname + '/fixtures/' + file;573- res.sendfile(path);574- });575- 576- assert.response(app,577- { url: '/large.json', headers: { 'Range': 'basdytes=asdf' }},578- { body: 'Requested Range Not Satisfiable', status: 416 });579- },580- 581- 'test #sendfile() Range invalid range': function(){582- var app = express.createServer();583- 584- app.get('/*', function(req, res, next){585- var file = req.params[0]586- , path = __dirname + '/fixtures/' + file;587- res.sendfile(path);588- });589- 590- assert.response(app,591- { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},592- { body: 'Requested Range Not Satisfiable', status: 416 });593- },594- 595- 'test #download()': function(beforeExit){596- var app = express.createServer()597- , calls = 0;598- 599- app.get('/json', function(req, res, next){600- var path = __dirname + '/fixtures/user.json';601- res.download(path, 'account.json');602- });603-604- app.get('/callback', function(req, res, next){605- res.download(__dirname + '/fixtures/pets.json', function(err){606- ++calls;607- });608- });609-610- app.get('/*', function(req, res, next){611- res.download(__dirname + '/fixtures/' + req.params[0]);612- });613-614- assert.response(app,615- { url: '/callback' },616- { body: '["tobi", "loki", "jane"]' });617-618- assert.response(app,619- { url: '/user.json' },620- { body: '{"name":"tj"}', status: 200, headers: {621- 'Content-Type': 'application/json',622- 'Content-Disposition': 'attachment; filename="user.json"'623- }});624- 625- assert.response(app,626- { url: '/json' },627- { body: '{"name":"tj"}', status: 200, headers: {628- 'Content-Type': 'application/json',629- 'Content-Length': '13',630- 'Content-Disposition': 'attachment; filename="account.json"'631- }});632- 633- assert.response(app,634- { url: '/missing' },635- function(res){636- assert.equal(null, res.headers['content-disposition']);637- });638-639- assert.response(app,640- { url: '/some%20random%20text%20file.txt' },641- { body: 'hello' });642-643- beforeExit(function(){644- calls.should.equal(1);645- });646- },647- 648- 'test #cookie() path default': function(){649- var app = express.createServer();650-651- app.set('home', '/foo');652-653- app.get('/', function(req, res){654- res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });655- res.cookie('something', 'else');656- res.redirect('/');657- });658-659- assert.response(app,660- { url: '/', headers: { Host: 'foo.com' }},661- function(res){662- res.headers['set-cookie']663- .should.eql(['rememberme=yes; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/foo']);664- });665- },666-667- 'test #cookie() explicit path': function(){668- var app = express.createServer();669-670- app.set('/home', '/foo');671-672- app.get('/', function(req, res){673- res.cookie('rememberme', 'yes', { path: '/', expires: new Date(1), httpOnly: true });674- res.cookie('something', 'else');675- res.redirect('/');676- });677-678- assert.response(app,679- { url: '/', headers: { Host: 'foo.com' }},680- function(res){681- res.headers['set-cookie']682- .should.eql(['rememberme=yes; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/']);683- });684- },685-686- 'test #cookie() null path': function(){687- var app = express.createServer();688-689- app.set('/home', '/foo');690-691- app.get('/', function(req, res){692- res.cookie('rememberme', 'yes', { path: null, expires: new Date(1), httpOnly: true });693- res.cookie('something', 'else', { path: null });694- res.redirect('/');695- });696-697- assert.response(app,698- { url: '/', headers: { Host: 'foo.com' }},699- function(res){700- res.headers['set-cookie']701- .should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);702- });703- },704-705- 'test #clearCookie() default path': function(){706- var app = express.createServer();707-708- app.set('home', '/foo');709-710- app.get('/', function(req, res){711- res.clearCookie('rememberme');712- res.redirect('/');713- });714- 715- assert.response(app,716- { url: '/' },717- function(res){718- res.headers['set-cookie']719- .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);720- });721- },722-723- 'test #clearCookie() explicit path': function(){724- var app = express.createServer();725-726- app.set('home', '/bar');727-728- app.get('/', function(req, res){729- res.clearCookie('rememberme', { path: '/foo' });730- res.redirect('/');731- });732- 733- assert.response(app,734- { url: '/' },735- function(res){736- res.headers['set-cookie']737- .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);738- });739- },740-741- 'test HEAD': function(){742- var app = express.createServer();743- 744- app.get('/', function(req, res, next){745- res.send('Hello World');746- });747- 748- assert.response(app,749- { url: '/', method: 'HEAD' },750- { body: '', headers: { 'Content-Length': 11 }});751- },752- 753- 'test .charset with res.send()': function(){754- var app = express.createServer();755-756- app.get('/', function(req, res){757- res.charset = 'ISO-8859-1';758- res.send('<p>hey</p>');759- });760-761- assert.response(app,762- { url: '/' },763- { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});764- }46+ // 47+ // 'test #status()': function(){48+ // var app = express.createServer();49+ // 50+ // app.get('/error', function(req, res, next){51+ // res.status(500).send('OH NO');52+ // });53+ // 54+ // assert.response(app,55+ // { url: '/error' },56+ // { body: 'OH NO', status: 500 });57+ // },58+ // 59+ // 'test #send()': function(){60+ // var app = express.createServer();61+ // 62+ // app.get('/html', function(req, res){63+ // res.send('<p>test</p>');64+ // });65+ // 66+ // app.get('/json', function(req, res){67+ // res.header('X-Foo', 'bar');68+ // res.send({ foo: 'bar' }, 201);69+ // });70+ // 71+ // app.get('/text', function(req, res){72+ // res.header('X-Foo', 'bar');73+ // res.contentType('txt');74+ // res.send('wahoo');75+ // });76+ // 77+ // app.get('/status', function(req, res){78+ // res.send(404);79+ // });80+ // 81+ // app.get('/status/text', function(req, res){82+ // res.send('Oh noes!', 404);83+ // });84+ // 85+ // app.get('/error', function(req, res){86+ // res.send('Oh shit!', 500);87+ // });88+ // 89+ // app.get('/buffer', function(req, res){90+ // res.send(new Buffer('wahoo!'));91+ // });92+ // 93+ // app.get('/204', function(req, res, next){94+ // res.send(204);95+ // });96+ // 97+ // app.get('/undefined', function(req, res, next){98+ // res.send(undefined);99+ // });100+ // 101+ // app.get('/bool', function(req, res, next){102+ // res.send(true);103+ // });104+ // 105+ // assert.response(app,106+ // { url: '/bool' },107+ // { body: 'true'108+ // , headers: { 'Content-Type': 'application/json; charset=utf-8' }});109+ // 110+ // assert.response(app,111+ // { url: '/html' },112+ // { body: '<p>test</p>'113+ // , headers: {114+ // 'Content-Type': 'text/html; charset=utf-8'115+ // }});116+ // 117+ // assert.response(app,118+ // { url: '/json' },119+ // { body: '{"foo":"bar"}'120+ // , status: 201121+ // , headers: {122+ // 'Content-Type': 'application/json; charset=utf-8'123+ // , 'X-Foo': 'baz'124+ // }});125+ // 126+ // assert.response(app,127+ // { url: '/text' },128+ // { body: 'wahoo'129+ // , headers: {130+ // 'Content-Type': 'text/plain'131+ // , 'X-Foo': 'bar'132+ // }});133+ // 134+ // assert.response(app,135+ // { url: '/status/text' },136+ // { body: 'Oh noes!', status: 404 });137+ // 138+ // assert.response(app,139+ // { url: '/status' },140+ // { body: 'Not Found'141+ // , status: 404142+ // , headers: { 'Content-Type': 'text/plain' }});143+ // 144+ // assert.response(app,145+ // { url: '/error' },146+ // { body: 'Oh shit!'147+ // , status: 500148+ // , headers: {149+ // 'Content-Type': 'text/plain; charset=utf-8'150+ // , 'Content-Length': '8'151+ // }});152+ // 153+ // assert.response(app,154+ // { url: '/buffer' },155+ // { body: 'wahoo!'156+ // , headers: {157+ // 'Content-Type': 'application/octet-stream'158+ // , 'Content-Length': '6'159+ // }});160+ // 161+ // assert.response(app,162+ // { url: '/204' },163+ // { status: 204 }, function(res){164+ // assert.equal(undefined, res.headers['content-type']);165+ // assert.equal(undefined, res.headers['content-length']);166+ // });167+ // 168+ // assert.response(app,169+ // { url: '/undefined' },170+ // { status: 500 });171+ // 172+ // assert.response(app,173+ // { url: '/json?callback=test' },174+ // { body: '{"foo":"bar"}'175+ // , status: 201176+ // , headers: {177+ // 'Content-Type': 'application/json; charset=utf-8'178+ // , 'X-Foo': 'baz'179+ // }});180+ // },181+ // 182+ // 'test #send() JSONP': function(){183+ // var app = express.createServer();184+ // 185+ // app.enable('jsonp callback');186+ // 187+ // app.get('/jsonp', function(req, res){188+ // res.header('X-Foo', 'bar');189+ // res.send({ foo: 'bar' }, 201);190+ // });191+ // 192+ // assert.response(app,193+ // { url: '/jsonp?callback=test' },194+ // { body: 'test({"foo":"bar"});'195+ // , status: 201196+ // , headers: {197+ // 'Content-Type': 'text/javascript; charset=utf-8'198+ // , 'X-Foo': 'bar'199+ // }});200+ // 201+ // assert.response(app,202+ // { url: '/jsonp?callback=baz' },203+ // { body: 'baz({"foo":"bar"});'204+ // , status: 201, headers: {205+ // 'Content-Type': 'text/javascript; charset=utf-8'206+ // , 'X-Foo': 'bar'207+ // }});208+ // 209+ // assert.response(app,210+ // { url: '/jsonp?callback=invalid()[]' },211+ // { body: 'invalid({"foo":"bar"});'212+ // , status: 201213+ // , headers: {214+ // 'Content-Type': 'text/javascript; charset=utf-8'215+ // , 'X-Foo': 'bar'216+ // }});217+ // },218+ // 219+ // 'test #json() JSONP': function(){220+ // var app = express.createServer();221+ // 222+ // app.enable('jsonp callback');223+ // 224+ // app.get('/jsonp', function(req, res){225+ // res.header('X-Foo', 'bar');226+ // res.json({ foo: 'bar' }, 201);227+ // });228+ // 229+ // assert.response(app,230+ // { url: '/jsonp?callback=test' },231+ // { body: 'test({"foo":"bar"});'232+ // , status: 201233+ // , headers: {234+ // 'Content-Type': 'text/javascript; charset=utf-8'235+ // , 'X-Foo': 'bar'236+ // }});237+ // 238+ // assert.response(app,239+ // { url: '/jsonp?callback=baz' },240+ // { body: 'baz({"foo":"bar"});'241+ // , status: 201, headers: {242+ // 'Content-Type': 'text/javascript; charset=utf-8'243+ // , 'X-Foo': 'bar'244+ // }});245+ // 246+ // assert.response(app,247+ // { url: '/jsonp?callback=invalid()[]' },248+ // { body: 'invalid({"foo":"bar"});'249+ // , status: 201250+ // , headers: {251+ // 'Content-Type': 'text/javascript; charset=utf-8'252+ // , 'X-Foo': 'bar'253+ // }});254+ // },255+ // 256+ // 'test #contentType()': function(){257+ // var app = express.createServer();258+ // 259+ // app.get('/html', function(req, res){260+ // res.contentType('index.html');261+ // res.writeHead(200, res.headers);262+ // res.end('<p>yay</p>');263+ // });264+ // 265+ // app.get('/json', function(req, res, next){266+ // res.contentType('json');267+ // res.send('{"foo":"bar"}');268+ // });269+ // 270+ // app.get('/literal', function(req, res){271+ // res.contentType('application/json');272+ // res.send('{"foo":"bar"}')273+ // });274+ // 275+ // assert.response(app,276+ // { url: '/literal' },277+ // { headers: { 'Content-Type': 'application/json' }}); 278+ // assert.response(app,279+ // { url: '/html' },280+ // { body: '<p>yay</p>', headers: { 'Content-Type': 'text/html' }});281+ // assert.response(app,282+ // { url: '/json' },283+ // { headers: { 'Content-Type': 'application/json' }});284+ // },285+ // 286+ // 'test #attachment()': function(){287+ // var app = express.createServer();288+ // 289+ // app.get('/style.css', function(req, res){290+ // res.attachment();291+ // res.send('some stylezzz');292+ // });293+ // 294+ // app.get('/*', function(req, res){295+ // res.attachment(req.params[0]);296+ // res.send('whatever');297+ // });298+ // 299+ // assert.response(app,300+ // { url: '/javascripts/jquery.js' },301+ // { body: 'whatever'302+ // , headers: { 'Content-Type': 'application/javascript'303+ // , 'Content-Disposition': 'attachment; filename="jquery.js"' }});304+ // 305+ // assert.response(app,306+ // { url: '/style.css' },307+ // { body: 'some stylezzz'308+ // , headers: { 'Content-Type': 'text/html; charset=utf-8'309+ // , 'Content-Disposition': 'attachment' }});310+ // },311+ // 312+ // 'test #redirect()': function(){313+ // var app = express.createServer()314+ // , app2 = express.createServer();315+ // 316+ // app2.set('home', '/blog');317+ // 318+ // app2.redirect('google', 'http://google.com');319+ // 320+ // app2.redirect('blog', function(req, res){321+ // return req.params.id322+ // ? '/user/' + req.params.id + '/blog'323+ // : null;324+ // });325+ // 326+ // app.get('/', function(req, res){327+ // res.redirect('http://google.com', 301);328+ // });329+ // 330+ // app.get('/back', function(req, res){331+ // res.redirect('back');332+ // });333+ // 334+ // app.get('/home', function(req, res){335+ // res.redirect('home');336+ // });337+ // 338+ // app.get('/html', function(req, res){339+ // res.redirect('http://google.com');340+ // });341+ // 342+ // app2.get('/', function(req, res){343+ // res.redirect('http://google.com', 301);344+ // });345+ // 346+ // app2.get('/back', function(req, res){347+ // res.redirect('back');348+ // });349+ // 350+ // app2.get('/home', function(req, res){351+ // res.redirect('home');352+ // });353+ // 354+ // app2.get('/google', function(req, res){355+ // res.redirect('google');356+ // });357+ // 358+ // app2.get('/user/:id', function(req, res){359+ // res.header('X-Foo', 'bar');360+ // res.redirect('blog');361+ // });362+ // 363+ // assert.response(app,364+ // { url: '/html', headers: { Accept: 'text/html,text/plain', Host: 'foo.com' }},365+ // { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });366+ // 367+ // assert.response(app,368+ // { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},369+ // { body: 'Moved Permanently. Redirecting to http://google.com'370+ // , status: 301, headers: { Location: 'http://google.com' }});371+ // 372+ // assert.response(app,373+ // { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},374+ // { body: 'Moved Temporarily. Redirecting to http://foo.com/'375+ // , status: 302, headers: { Location: 'http://foo.com/', 'Content-Type': 'text/plain' }});376+ // 377+ // assert.response(app,378+ // { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},379+ // { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'380+ // , status: 302, headers: { Location: 'http://foo.com/foo' }});381+ // 382+ // assert.response(app,383+ // { url: '/back', headers: { Referrer: '/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' }});386+ // 387+ // assert.response(app,388+ // { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' } },389+ // { body: 'Moved Temporarily. Redirecting to http://foo.com/'390+ // , status: 302, headers: { Location: 'http://foo.com/' }});391+ // 392+ // assert.response(app2,393+ // { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},394+ // { body: 'Moved Permanently. Redirecting to http://google.com'395+ // , status: 301, headers: { Location: 'http://google.com' }});396+ // 397+ // assert.response(app2,398+ // { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},399+ // { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'400+ // , status: 302, headers: { Location: 'http://foo.com/blog' }});401+ // 402+ // assert.response(app2,403+ // { url: '/home', 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' }});406+ // 407+ // assert.response(app2,408+ // { url: '/google', headers: { Accept: 'text/plain', Host: 'foo.com' }},409+ // { body: 'Moved Temporarily. Redirecting to http://google.com'410+ // , status: 302, headers: { Location: 'http://google.com' }});411+ // 412+ // assert.response(app2,413+ // { url: '/user/12', headers: { Accept: 'text/plain', Host: 'foo.com' }},414+ // { body: 'Moved Temporarily. Redirecting to http://foo.com/user/12/blog'415+ // , status: 302, headers: { Location: 'http://foo.com/user/12/blog', 'X-Foo': 'bar' }});416+ // },417+ // 418+ // 'test #redirect() when mounted': function(){419+ // var app = express.createServer()420+ // , blog = express.createServer();421+ // 422+ // 423+ // blog.get('/posts', function(req, res){424+ // res.redirect('/posts/all');425+ // });426+ // 427+ // blog.get('/posts/all', function(req, res){428+ // res.send('all blog posts');429+ // });430+ // 431+ // app.use('/blog', blog);432+ // 433+ // assert.response(app,434+ // { url: '/blog/posts', headers: { Host: 'foo.com' }},435+ // { status: 302436+ // , headers: { Location: 'http://foo.com/blog/posts/all' }});437+ // },438+ // 439+ // 'test #sendfile()': function(){440+ // var app = express.createServer();441+ // 442+ // app.get('/*', function(req, res, next){443+ // var file = req.params[0]444+ // , path = __dirname + '/fixtures/' + file;445+ // res.sendfile(path);446+ // });447+ // 448+ // app.use(express.errorHandler());449+ // 450+ // assert.response(app,451+ // { url: '/../express.test.js' },452+ // { body: 'Forbidden', status: 403 });453+ // 454+ // assert.response(app,455+ // { url: '/user.json' },456+ // { body: '{"name":"tj"}'457+ // , status: 200, headers: { 'Content-Type': 'application/json' }});458+ // 459+ // assert.response(app,460+ // { url: '/hello.haml' },461+ // { body: '%p Hello World'462+ // , status: 200, headers: { 'Content-Type': 'application/octet-stream' }});463+ // 464+ // assert.response(app,465+ // { url: '/doesNotExist' },466+ // { body: 'Cannot GET /doesNotExist', status: 404 });467+ // 468+ // assert.response(app,469+ // { url: '/partials' },470+ // { body: 'Cannot GET /partials', status: 404 });471+ // 472+ // assert.response(app,473+ // { url: '/large.json' },474+ // { status: 200, headers: { 'Content-Type': 'application/json' }});475+ // },476+ // 477+ // 'test #sendfile(path, callback)': function(beforeExit){478+ // var app = express.createServer()479+ // , calls = 0;480+ // 481+ // app.get('/*', function(req, res, next){482+ // var file = req.params[0]483+ // , path = __dirname + '/fixtures/' + file;484+ // res.sendfile(path, function(err){485+ // if (err) return res.send('got an error');486+ // ++calls;487+ // });488+ // });489+ // 490+ // assert.response(app,491+ // { url: '/forum' },492+ // { body: 'got an error' });493+ // 494+ // assert.response(app,495+ // { url: '/does-not-exist' },496+ // { body: 'got an error' });497+ // 498+ // assert.response(app,499+ // { url: '/large.json' },500+ // { headers: { 'Accept-Ranges': 'bytes' }});501+ // 502+ // beforeExit(function(){503+ // calls.should.equal(1);504+ // });505+ // },506+ // 507+ // 'test #sendfile(path, options, callback)': function(beforeExit){508+ // var app = express.createServer()509+ // , calls = 0;510+ // 511+ // app.get('/*', function(req, res, next){512+ // var file = req.params[0]513+ // , path = __dirname + '/fixtures/' + file;514+ // res.sendfile(path, { maxAge: 3600000 }, function(err){515+ // if (err) return res.send('got an error');516+ // ++calls;517+ // });518+ // });519+ // 520+ // assert.response(app,521+ // { url: '/does-not-exist' },522+ // { body: 'got an error' });523+ // 524+ // assert.response(app,525+ // { url: '/large.json' },526+ // { headers: {527+ // 'Accept-Ranges': 'bytes'528+ // , 'Cache-Control': 'public, max-age=3600'529+ // }});530+ // 531+ // beforeExit(function(){532+ // calls.should.equal(1);533+ // });534+ // },535+ // 536+ // 'test #sendfile() Accept-Ranges': function(){537+ // var app = express.createServer();538+ // 539+ // app.get('/*', function(req, res, next){540+ // var file = req.params[0]541+ // , path = __dirname + '/fixtures/' + file;542+ // res.sendfile(path);543+ // });544+ // 545+ // assert.response(app,546+ // { url: '/large.json' },547+ // { headers: { 'Accept-Ranges': 'bytes' }});548+ // },549+ // 550+ // 'test #sendfile() Range': function(){551+ // var app = express.createServer();552+ // 553+ // app.get('/*', function(req, res, next){554+ // var file = req.params[0]555+ // , path = __dirname + '/fixtures/' + file;556+ // res.sendfile(path);557+ // });558+ // 559+ // assert.response(app,560+ // { url: '/large.json', headers: { 'Range': 'bytes=0-499' }},561+ // { headers: {562+ // 'Content-Type': 'application/json',563+ // 'Content-Range': 'bytes 0-499/2535'564+ // }, status: 206 });565+ // },566+ // 567+ // 'test #sendfile() Range invalid syntax': function(){568+ // var app = express.createServer();569+ // 570+ // app.get('/*', function(req, res, next){571+ // var file = req.params[0]572+ // , path = __dirname + '/fixtures/' + file;573+ // res.sendfile(path);574+ // });575+ // 576+ // assert.response(app,577+ // { url: '/large.json', headers: { 'Range': 'basdytes=asdf' }},578+ // { body: 'Requested Range Not Satisfiable', status: 416 });579+ // },580+ // 581+ // 'test #sendfile() Range invalid range': function(){582+ // var app = express.createServer();583+ // 584+ // app.get('/*', function(req, res, next){585+ // var file = req.params[0]586+ // , path = __dirname + '/fixtures/' + file;587+ // res.sendfile(path);588+ // });589+ // 590+ // assert.response(app,591+ // { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},592+ // { body: 'Requested Range Not Satisfiable', status: 416 });593+ // },594+ // 595+ // 'test #download()': function(beforeExit){596+ // var app = express.createServer()597+ // , calls = 0;598+ // 599+ // app.get('/json', function(req, res, next){600+ // var path = __dirname + '/fixtures/user.json';601+ // res.download(path, 'account.json');602+ // });603+ // 604+ // app.get('/callback', function(req, res, next){605+ // res.download(__dirname + '/fixtures/pets.json', function(err){606+ // ++calls;607+ // });608+ // });609+ // 610+ // app.get('/*', function(req, res, next){611+ // res.download(__dirname + '/fixtures/' + req.params[0]);612+ // });613+ // 614+ // assert.response(app,615+ // { url: '/callback' },616+ // { body: '["tobi", "loki", "jane"]' });617+ // 618+ // assert.response(app,619+ // { url: '/user.json' },620+ // { body: '{"name":"tj"}', status: 200, headers: {621+ // 'Content-Type': 'application/json',622+ // 'Content-Disposition': 'attachment; filename="user.json"'623+ // }});624+ // 625+ // assert.response(app,626+ // { url: '/json' },627+ // { body: '{"name":"tj"}', status: 200, headers: {628+ // 'Content-Type': 'application/json',629+ // 'Content-Length': '13',630+ // 'Content-Disposition': 'attachment; filename="account.json"'631+ // }});632+ // 633+ // assert.response(app,634+ // { url: '/missing' },635+ // function(res){636+ // assert.equal(null, res.headers['content-disposition']);637+ // });638+ // 639+ // assert.response(app,640+ // { url: '/some%20random%20text%20file.txt' },641+ // { body: 'hello' });642+ // 643+ // beforeExit(function(){644+ // calls.should.equal(1);645+ // });646+ // },647+ // 648+ // 'test #cookie() path default': function(){649+ // var app = express.createServer();650+ // 651+ // app.set('home', '/foo');652+ // 653+ // app.get('/', function(req, res){654+ // res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });655+ // res.cookie('something', 'else');656+ // res.redirect('/');657+ // });658+ // 659+ // assert.response(app,660+ // { url: '/', headers: { Host: 'foo.com' }},661+ // function(res){662+ // res.headers['set-cookie']663+ // .should.eql(['rememberme=yes; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/foo']);664+ // });665+ // },666+ // 667+ // 'test #cookie() explicit path': function(){668+ // var app = express.createServer();669+ // 670+ // app.set('/home', '/foo');671+ // 672+ // app.get('/', function(req, res){673+ // res.cookie('rememberme', 'yes', { path: '/', expires: new Date(1), httpOnly: true });674+ // res.cookie('something', 'else');675+ // res.redirect('/');676+ // });677+ // 678+ // assert.response(app,679+ // { url: '/', headers: { Host: 'foo.com' }},680+ // function(res){681+ // res.headers['set-cookie']682+ // .should.eql(['rememberme=yes; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/']);683+ // });684+ // },685+ // 686+ // 'test #cookie() null path': function(){687+ // var app = express.createServer();688+ // 689+ // app.set('/home', '/foo');690+ // 691+ // app.get('/', function(req, res){692+ // res.cookie('rememberme', 'yes', { path: null, expires: new Date(1), httpOnly: true });693+ // res.cookie('something', 'else', { path: null });694+ // res.redirect('/');695+ // });696+ // 697+ // assert.response(app,698+ // { url: '/', headers: { Host: 'foo.com' }},699+ // function(res){700+ // res.headers['set-cookie']701+ // .should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);702+ // });703+ // },704+ // 705+ // 'test #clearCookie() default path': function(){706+ // var app = express.createServer();707+ // 708+ // app.set('home', '/foo');709+ // 710+ // app.get('/', function(req, res){711+ // res.clearCookie('rememberme');712+ // res.redirect('/');713+ // });714+ // 715+ // assert.response(app,716+ // { url: '/' },717+ // function(res){718+ // res.headers['set-cookie']719+ // .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);720+ // });721+ // },722+ // 723+ // 'test #clearCookie() explicit path': function(){724+ // var app = express.createServer();725+ // 726+ // app.set('home', '/bar');727+ // 728+ // app.get('/', function(req, res){729+ // res.clearCookie('rememberme', { path: '/foo' });730+ // res.redirect('/');731+ // });732+ // 733+ // assert.response(app,734+ // { url: '/' },735+ // function(res){736+ // res.headers['set-cookie']737+ // .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);738+ // });739+ // },740+ // 741+ // 'test HEAD': function(){742+ // var app = express.createServer();743+ // 744+ // app.get('/', function(req, res, next){745+ // res.send('Hello World');746+ // });747+ // 748+ // assert.response(app,749+ // { url: '/', method: 'HEAD' },750+ // { body: '', headers: { 'Content-Length': 11 }});751+ // },752+ // 753+ // 'test .charset with res.send()': function(){754+ // var app = express.createServer();755+ // 756+ // app.get('/', function(req, res){757+ // res.charset = 'ISO-8859-1';758+ // res.send('<p>hey</p>');759+ // });760+ // 761+ // assert.response(app,762+ // { url: '/' },763+ // { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});764+ // }765 };modified:test/router.test.js+55 added-55 removed
74 unmodified lines75 },76 77 'test precedence': function(){78 var app = express.createServer();79-79+ 80 var hits = [];81-81+ 82 app.all('*', function(req, res, next){83 hits.push('all');84 next();85 });86-86+ 87 app.get('/foo', function(req, res, next){88 hits.push('GET /foo');89 next();90 });1 unmodified line92 app.get('/foo', function(req, res, next){93 hits.push('GET /foo2');94 next();95 });96-96+ 97 app.put('/foo', function(req, res, next){98 hits.push('PUT /foo');99 next();100 });101-101+ 102 assert.response(app,103 { url: '/foo' },104 function(){105 hits.should.eql(['all', 'GET /foo', 'GET /foo2']);106 });107 },108-108+ 109 'test named capture groups': function(){110 var app = express.createServer();111-111+ 112 app.get('/user/:id([0-9]{2,10})', function(req, res){113 res.send('user ' + req.params.id);114 });115-115+ 116 app.post('/pin/save/:lat(\\d+.\\d+)/:long(\\d+.\\d+)', function(req, res){117 res.send(req.params.lat + ' ' + req.params.long);118 });119-119+ 120 app.post('/pin/save2/:lat([0-9]+.[0-9]+)/:long([0-9]+.[0-9]+)', function(req, res){121 res.send(req.params.lat + ' ' + req.params.long);122 });123-123+ 124 assert.response(app,125 { url: '/pin/save/1.2/3.4', method: 'POST' },126 { body: '1.2 3.4' });127-127+ 128 assert.response(app,129 { url: '/pin/save2/1.2/3.4', method: 'POST' },130 { body: '1.2 3.4' });131-131+ 132 assert.response(app,133 { url: '/user/12' },134 { body: 'user 12' });135 3 unmodified lines139 },140 141 'test app.param()': function(){142 var app = express.createServer();143-143+ 144 var users = [145 { name: 'tj' }146 , { name: 'tobi' }147 , { name: 'loki' }148 , { name: 'jane' }149 , { name: 'bandit' }150 ];151-151+ 152 app.param('user', function(req, res, next, id){153 if (req.user = users[id]) {154 next();155 } else {156 next(new Error('failed to find user'));157 }158 });159-159+ 160 app.get('/user/:user', function(req, res, next){161 res.send('user ' + req.user.name);162 });163-163+ 164 assert.response(app,165 { url: '/user/0' },166 { body: 'user tj' });167 168 assert.response(app,169 { url: '/user/1' },170 { body: 'user tobi' });171 },172-172+ 173 'test app.param() optional execution': function(beforeExit){174 var app = express.createServer()175 , calls = 0;176-176+ 177 var months = ['Jan', 'Feb', 'Mar'];178-178+ 179 app.param('month', function(req, res, next, n){180 req.params.month = months[n];181 ++calls;182 next();183 });184-184+ 185 app.get('/calendar/:month?', function(req, res, next){186 res.send(req.params.month || months[0]);187 });188-188+ 189 assert.response(app,190 { url: '/calendar' },191 { body: 'Jan' });192-192+ 193 assert.response(app,194 { url: '/calendar/1' },195 { body: 'Feb' });196-196+ 197 beforeExit(function(){198 calls.should.equal(1);199 });200 },20 unmodified lines221 app.get('/user/:id', function(){});222 app.get('/user/:id/:op?', function(){});223 app.put('/user/:id', function(){});224 app.get('/user/:id/edit', function(){});225-225+ 226 var route = app.get('/user/:id')[0]227 route.should.be.an.instanceof(Route);228 route.callback.should.be.a('function');229 route.path.should.equal('/user/:id');230 route.regexp.should.be.an.instanceof(RegExp);231 route.method.should.equal('get');232 route.keys.should.eql([{ name: 'id', optional: false }]);233-233+ 234 app.get('/user').should.have.length(1);235 app.get('/user/:id').should.have.length(1);236 app.get('/user/:id/:op?').should.have.length(1);237 app.put('/user/:id').should.have.length(1);238 app.get('/user/:id/edit').should.have.length(1);239 app.get('/').should.have.be.empty;240 app.all('/user/:id').should.have.length(2);241-241+ 242 app.lookup.get('/user').should.have.length(1);243 app.lookup.get('/user/:id').should.have.length(1);244 app.lookup.get('/user/:id/:op?').should.have.length(1);245 app.lookup.put('/user/:id').should.have.length(1);1 unmodified line247 app.lookup.get('/').should.have.be.empty;248 app.lookup.all('/user/:id').should.have.length(2);249 app.lookup('/user/:id').should.have.length(2);250 },251-251+ 252 'test app.remove': function(){253 var app = express.createServer();254 app.get('/user', function(){});255 app.get('/user', function(){});256 app.put('/user', function(){});257-257+ 258 app.get('/user').should.have.length(2);259 var removed = app.remove.get('/user');260 removed.should.have.length(2);261-261+ 262 var removed = app.remove.get('/user');263 removed.should.have.length(0);264 app.get('/user').should.have.length(0);265-265+ 266 app.get('/user/:id', function(){});267 app.put('/user/:id', function(){});268 app.del('/user/:id', function(){});269-269+ 270 app.remove.all('/user/:id').should.have.length(3);271 app.remove.all('/user/:id').should.have.length(0);272 273 app.get('/user/:id', function(){});274 app.put('/user/:id', function(){});275 app.del('/user/:id', function(){});276-276+ 277 app.remove('/user/:id').should.have.length(3);278 },279 280 'test app.match': function(){2 unmodified lines283 app.get('/user/:id', function(){});284 app.get('/user/:id/:op?', function(){});285 app.put('/user/:id', function(){});286 app.get('/user/:id/edit', function(){});287-287+ 288 var route = app.match.get('/user/12')[0];289 route.should.be.an.instanceof(Route);290 route.callback.should.be.a('function');291 route.path.should.equal('/user/:id');292 route.regexp.should.be.an.instanceof(RegExp);293 route.method.should.equal('get');294 route.keys.should.eql([{ name: 'id', optional: false }]);295 //route.params.id.should.equal('12');296-296+ 297 app.match.get('/user').should.have.length(1);298 app.match.get('/user/12').should.have.length(2);299 app.match.get('/user/12/:op?').should.have.length(1);300 app.match.put('/user/100').should.have.length(1);1 unmodified line302 app.match.get('/').should.have.be.empty;303 app.match.all('/user/123').should.have.length(3);304 app.match('/user/123').should.have.length(3);305 },306-306+ 307 'test Collection': function(){308 var app = express.createServer();309 app.get('/user', function(){});310 app.get('/user/:id', function(){});311 app.get('/user/:id/:op?', function(){});312 app.put('/user/:id', function(){});313 app.get('/user/:id/edit', function(){});314-314+ 315 var ret = app.match.all('/user/12').remove();316 ret.should.have.length(3);317 app.match.all('/user/12').should.have.length(0);318 app.get('/user/:id').should.have.length(0);319 },320-320+ 321 'test "strict routing" setting': function(){322 var app = express.createServer();323-323+ 324 app.enable('strict routing');325-325+ 326 app.get('/:path', function(req, res, next){327 res.send({ type: 'directory' });328 });329-329+ 330 app.get('/:path/', function(req, res, next){331 res.send(['.', '..', 'foo.js', 'bar.js']);332 });333-333+ 334 assert.response(app,335 { url: '/lib' },336 { body: '{"type":"directory"}' });337-337+ 338 assert.response(app,339 { url: '/lib/' },340 { body: '[".","..","foo.js","bar.js"]' });341 },342-342+ 343 'test "case sensitive routes" setting': function(){344 var app = express.createServer();345-345+ 346 app.enable('case sensitive routes');347-347+ 348 app.get('/account', function(req, res){349 res.send('account');350 });351 352 app.get('/Account', function(req, res){353 res.send('Account');354 });355-355+ 356 assert.response(app,357 { url: '/account' },358 { body: 'account' });359-359+ 360 assert.response(app,361 { url: '/Account' },362 { body: 'Account' });363 },364 365 'override OPTIONS default': function(){366 var app = express.createServer();367-367+ 368 app.get('/', function(req, res, next){369 370 });371-371+ 372 app.options('/foo', function(req, res, next){373 res.header('Allow', 'GET')374 res.send('whatever');375 });376-376+ 377 assert.response(app,378 { url: '/', method: 'OPTIONS' },379 { body: 'GET', headers: { Allow: 'GET' }});380-380+ 381 assert.response(app,382 { url: '/foo', method: 'OPTIONS' },383 { body: 'whatever', headers: { Allow: 'GET' }});384 },385 386 'test req.route': function(){387 var app = express.createServer();388-388+ 389 var routes = [];390-390+ 391 app.get('/:foo?', function(req, res, next){392 routes.push(req.route.path);393 next();394 });395-395+ 396 app.get('/foo', function(req, res, next){397 routes.push(req.route.path);398 next();399 });400-400+ 401 assert.response(app,402 { url: '/foo' },403 function(){404 routes.should.eql(['/:foo?', '/foo']);3 unmodified lines