Skip to content
Myr

Merge branch 'remove-header-fields'

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 · parents 986916c, 365b3a7 · Browse files · 4 files+173 added−194 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+173 added−194 removed

  • tests:+162 added−166 removed
  • other:+11 added−28 removed

4 files+173 added−194 removed

modified:lib/router/index.js+1 added-1 removed
264 unmodified lines
265266Router.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};271272/**273 * Return an array of HTTP verbs or "options" for `path`.
111 unmodified lines
modified:lib/response.js+10 added-27 removed
20 unmodified lines
21 , basename = path.basename22 , join = path.join;2324/**25 * Send a response with the given `body` and optional `headers` and `status` code.25 * Send a response with the given `body` and optional `status` code.26 *27 * Examples:28 *29 * res.send(new Buffer('wahoo'));30 * res.send({ some: 'json' });31 * res.send('<p>some html</p>');32 * res.send('Sorry, cant find that', 404);33 * res.send('text', { 'Content-Type': 'text/plain' }, 201);33 * res.send(404);34 *35 * @param {String|Object|Number|Buffer} body or status37 * @param {Object|Number} headers or status36 * @param {Number} status37 * @return {ServerResponse}38 * @api public39 */4043res.send = function(body, headers, status){44 // allow status as second arg45 if ('number' == typeof headers) {46 status = headers,47 headers = null;48 }4941res.send = function(body, status){42 // default status43 status = status || this.statusCode;4445 // determine content type
16 unmodified lines
62 if (!this.header('Content-Type')) {63 this.contentType('.bin');64 }65 } else {74 return this.json(body, headers, status);66 return this.json(body, status);67 }68 break;69 }70
3 unmodified lines
74 ? body.length75 : Buffer.byteLength(body));76 }7786 // merge headers passed87 if (headers) {88 var fields = Object.keys(headers);89 for (var i = 0, len = fields.length; i < len; ++i) {90 var field = fields[i];91 this.header(field, headers[field]);92 }93 }9478 // strip irrelevant headers79 if (204 == status || 304 == status) {80 this.removeHeader('Content-Type');81 this.removeHeader('Content-Length');
5 unmodified lines
87 return this;88};8990/**108 * Send JSON response with `obj`, optional `headers`, and optional `status`.91 * Send JSON response with `obj` and optional `status`.92 *93 * Examples:94 *95 * res.json(null);
1 unmodified line
97 * res.json('oh noes!', 500);98 * res.json('I dont have that', 404);99 *100 * @param {Mixed} obj118 * @param {Object|Number} headers or status101 * @param {Number} status102 * @param {Number} status103 * @return {ServerResponse}104 * @api public105 */106124res.json = function(obj, headers, status){107res.json = function(obj, status){108 var body = JSON.stringify(obj)109 , callback = this.req.query.callback110 , jsonp = this.app.enabled('jsonp callback');111
4 unmodified lines
116 this.header('Content-Type', 'text/javascript');117 body = callback.replace(/[^\w$.]/g, '') + '(' + body + ');';118 }119137 return this.send(body, headers, status);120 return this.send(body, status);121};122123/**124 * Set status `code`.
123 unmodified lines
248 * Set or get response header `name` with optional `val`.249 *250 * @param {String} name251 * @param {String} val269 * @return {String}252 * @return {ServerResponse} for chaining253 * @api public254 */255256res.header = function(name, val){274 if (val === undefined) {257 if (1 == arguments.length) {258 return this.getHeader(name);259 } else {260 this.setHeader(name, val);278 return val;261 return this;262 }263};264265/**
139 unmodified lines
modified:test/response.test.js+107 added-111 removed
23 unmodified lines
24 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 });3128 assert.response(app,29 { url: '/error' },30 { body: '"oh noes!"'31 , status: 500
10 unmodified lines
42 assert.response(app,43 { url: '/user' },44 { body: '{"name":"tj"}', headers: { 'Content-Type': json }});45 },5046 47 'test #status()': function(){48 var app = express.createServer();5349 50 app.get('/error', function(req, res, next){51 res.status(500).send('OH NO');52 });5753 54 assert.response(app,55 { url: '/error' },56 { body: 'OH NO', status: 500 });57 },6258 59 'test #send()': function(){60 var app = express.createServer();61 62 app.get('/html', function(req, res){67 res.send('<p>test</p>', { 'Content-Language': 'en' });63 res.send('<p>test</p>');64 });6965 66 app.get('/json', function(req, res){67 res.header('X-Foo', 'bar');72 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);68 res.send({ foo: 'bar' }, 201);69 });70 71 app.get('/text', function(req, res){72 res.header('X-Foo', 'bar');
9 unmodified lines
82 res.send('Oh noes!', 404);83 });84 85 app.get('/error', function(req, res){90 res.send('Oh shit!', { 'Content-Type': 'text/plain' }, 500);86 res.header('Content-Type', 'text/plain');87 res.send('Oh shit!', 500);88 });89 90 app.get('/buffer', function(req, res){91 res.send(new Buffer('wahoo!'));
5 unmodified lines
97 98 app.get('/undefined', function(req, res, next){99 res.send(undefined);100 });104101 102 app.get('/bool', function(req, res, next){103 res.send(true);104 });108105 106 assert.response(app,107 { url: '/bool' },108 { body: 'true'109 , headers: { 'Content-Type': 'application/json; charset=utf-8' }});113110 111 assert.response(app,112 { url: '/html' },113 { body: '<p>test</p>'114 , headers: {118 'Content-Language': 'en'119 , 'Content-Type': 'text/html; charset=utf-8'115 'Content-Type': 'text/html; charset=utf-8'116 }});121 117 118 assert.response(app,119 { url: '/json' },120 { body: '{"foo":"bar"}'121 , status: 201122 , headers: {123 'Content-Type': 'application/json; charset=utf-8'128 , 'X-Foo': 'baz'124 , 'X-Foo': 'bar'125 }});130 126 127 assert.response(app,128 { url: '/text' },129 { body: 'wahoo'130 , headers: {131 'Content-Type': 'text/plain'132 , 'X-Foo': 'bar'133 }});138134 135 assert.response(app,136 { url: '/status/text' },137 { body: 'Oh noes!', status: 404 });142138 139 assert.response(app,140 { url: '/status' },141 { body: 'Not Found'142 , status: 404143 , headers: { 'Content-Type': 'text/plain' }});148 144 145 assert.response(app,146 { url: '/error' },147 { body: 'Oh shit!'148 , status: 500149 , headers: {154 'Content-Type': 'text/plain; charset=utf-8'150 'Content-Type': 'text/plain'151 , 'Content-Length': '8'152 }});157 153 154 assert.response(app,155 { url: '/buffer' },156 { body: 'wahoo!'157 , headers: {158 'Content-Type': 'application/octet-stream'159 , 'Content-Length': '6'160 }});165 161 162 assert.response(app,163 { url: '/204' },164 { status: 204 }, function(res){165 assert.equal(undefined, res.headers['content-type']);166 assert.equal(undefined, res.headers['content-length']);167 });172168 169 assert.response(app,170 { url: '/undefined' },171 { status: 500 });176172 173 assert.response(app,174 { url: '/json?callback=test' },175 { body: '{"foo":"bar"}'176 , status: 201177 , headers: {178 'Content-Type': 'application/json; charset=utf-8'183 , 'X-Foo': 'baz'179 , 'X-Foo': 'bar'180 }});181 },186182 183 'test #send() JSONP': function(){184 var app = express.createServer();189185 186 app.enable('jsonp callback');191187 188 app.get('/jsonp', function(req, res){189 res.header('X-Foo', 'bar');194 res.send({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);190 res.send({ foo: 'bar' }, 201);191 });196192 193 assert.response(app,194 { url: '/jsonp?callback=test' },195 { body: 'test({"foo":"bar"});'196 , status: 201197 , headers: {198 'Content-Type': 'text/javascript; charset=utf-8'203 , 'X-Foo': 'baz'199 , 'X-Foo': 'bar'200 }});201 202 assert.response(app,203 { url: '/jsonp?callback=baz' },204 { body: 'baz({"foo":"bar"});'205 , status: 201, headers: {206 'Content-Type': 'text/javascript; charset=utf-8'211 , 'X-Foo': 'baz'207 , 'X-Foo': 'bar'208 }});209 210 assert.response(app,211 { url: '/jsonp?callback=invalid()[]' },212 { body: 'invalid({"foo":"bar"});'213 , status: 201214 , headers: {215 'Content-Type': 'text/javascript; charset=utf-8'220 , 'X-Foo': 'baz'216 , 'X-Foo': 'bar'217 }});218 },223219 220 'test #json() JSONP': function(){221 var app = express.createServer();226222 223 app.enable('jsonp callback');228224 225 app.get('/jsonp', function(req, res){226 res.header('X-Foo', 'bar');231 res.json({ foo: 'bar' }, { 'X-Foo': 'baz' }, 201);227 res.json({ foo: 'bar' }, 201);228 });233229 230 assert.response(app,231 { url: '/jsonp?callback=test' },232 { body: 'test({"foo":"bar"});'233 , status: 201234 , headers: {235 'Content-Type': 'text/javascript; charset=utf-8'240 , 'X-Foo': 'baz'236 , 'X-Foo': 'bar'237 }});238 239 assert.response(app,240 { url: '/jsonp?callback=baz' },241 { body: 'baz({"foo":"bar"});'242 , status: 201, headers: {243 'Content-Type': 'text/javascript; charset=utf-8'248 , 'X-Foo': 'baz'244 , 'X-Foo': 'bar'245 }});246 247 assert.response(app,248 { url: '/jsonp?callback=invalid()[]' },249 { body: 'invalid({"foo":"bar"});'250 , status: 201251 , headers: {252 'Content-Type': 'text/javascript; charset=utf-8'257 , 'X-Foo': 'baz'253 , 'X-Foo': 'bar'254 }});255 },260256 257 'test #contentType()': function(){258 var app = express.createServer();259 260 app.get('/html', function(req, res){
5 unmodified lines
266 app.get('/json', function(req, res, next){267 res.contentType('json');268 res.send('{"foo":"bar"}');269 });274270 271 app.get('/literal', function(req, res){272 res.contentType('application/json');273 res.send('{"foo":"bar"}')274 });279275 276 assert.response(app,277 { url: '/literal' },278 { headers: { 'Content-Type': 'application/json' }}); 279 assert.response(app,
10 unmodified lines
290 app.get('/style.css', function(req, res){291 res.attachment();292 res.send('some stylezzz');293 });298294 295 app.get('/*', function(req, res){296 res.attachment(req.params[0]);297 res.send('whatever');298 });
2 unmodified lines
301 { url: '/javascripts/jquery.js' },302 { body: 'whatever'303 , headers: { 'Content-Type': 'application/javascript'304 , 'Content-Disposition': 'attachment; filename="jquery.js"' }});309305 306 assert.response(app,307 { url: '/style.css' },308 { body: 'some stylezzz'309 , headers: { 'Content-Type': 'text/html; charset=utf-8'
4 unmodified lines
314 var app = express.createServer()315 , app2 = express.createServer();316 317 app2.set('home', '/blog');322318 319 app2.redirect('google', 'http://google.com');324320 321 app2.redirect('blog', function(req, res){322 return req.params.id323 ? '/user/' + req.params.id + '/blog'324 : null;
29 unmodified lines
354 355 app2.get('/google', function(req, res){356 res.redirect('google');357 });362358 359 app2.get('/user/:id', function(req, res){360 res.header('X-Foo', 'bar');361 res.redirect('blog');362 });367363 364 assert.response(app,365 { url: '/html', headers: { Accept: 'text/html,text/plain', Host: 'foo.com' }},366 { body: '<p>Moved Temporarily. Redirecting to <a href="http://google.com">http://google.com</a></p>' });371367 368 assert.response(app,369 { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},370 { body: 'Moved Permanently. Redirecting to http://google.com'371 , status: 301, headers: { Location: 'http://google.com' }});376372 373 assert.response(app,374 { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},375 { body: 'Moved Temporarily. Redirecting to http://foo.com/'376 , status: 302, headers: { Location: 'http://foo.com/', 'Content-Type': 'text/plain' }});381377 378 assert.response(app,379 { url: '/back', headers: { Referer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},380 { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'381 , status: 302, headers: { Location: 'http://foo.com/foo' }});386382 383 assert.response(app,384 { url: '/back', headers: { Referrer: '/foo', Accept: 'text/plain', Host: 'foo.com' }},385 { body: 'Moved Temporarily. Redirecting to http://foo.com/foo'386 , status: 302, headers: { Location: 'http://foo.com/foo' }});391387 388 assert.response(app,389 { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' } },390 { body: 'Moved Temporarily. Redirecting to http://foo.com/'391 , status: 302, headers: { Location: 'http://foo.com/' }});396392 393 assert.response(app2,394 { url: '/', headers: { Accept: 'text/plain', Host: 'foo.com' }},395 { body: 'Moved Permanently. Redirecting to http://google.com'396 , status: 301, headers: { Location: 'http://google.com' }});401397 398 assert.response(app2,399 { url: '/back', headers: { Accept: 'text/plain', Host: 'foo.com' }},400 { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'401 , status: 302, headers: { Location: 'http://foo.com/blog' }});406402 403 assert.response(app2,404 { url: '/home', headers: { Accept: 'text/plain', Host: 'foo.com' }},405 { body: 'Moved Temporarily. Redirecting to http://foo.com/blog'406 , status: 302, headers: { Location: 'http://foo.com/blog' }});411407 408 assert.response(app2,409 { url: '/google', headers: { Accept: 'text/plain', Host: 'foo.com' }},410 { body: 'Moved Temporarily. Redirecting to http://google.com'411 , status: 302, headers: { Location: 'http://google.com' }});416412 413 assert.response(app2,414 { url: '/user/12', headers: { Accept: 'text/plain', Host: 'foo.com' }},415 { body: 'Moved Temporarily. Redirecting to http://foo.com/user/12/blog'416 , status: 302, headers: { Location: 'http://foo.com/user/12/blog', 'X-Foo': 'bar' }});417 },422418 419 'test #redirect() when mounted': function(){420 var app = express.createServer()421 , blog = express.createServer();426427422 423 424 blog.get('/posts', function(req, res){425 res.redirect('/posts/all');426 });431427 428 blog.get('/posts/all', function(req, res){429 res.send('all blog posts');430 });435431 432 app.use('/blog', blog);437433 434 assert.response(app,435 { url: '/blog/posts', headers: { Host: 'foo.com' }},436 { status: 302437 , headers: { Location: 'http://foo.com/blog/posts/all' }});438 },439 440 'test #sendfile()': function(){441 var app = express.createServer();446442 443 app.get('/*', function(req, res, next){444 var file = req.params[0]445 , path = __dirname + '/fixtures/' + file;446 res.sendfile(path);447 });448 449 app.use(express.errorHandler());454450 451 assert.response(app,452 { url: '/../express.test.js' },453 { body: 'Forbidden', status: 403 });458454 455 assert.response(app,456 { url: '/user.json' },457 { body: '{"name":"tj"}'458 , status: 200, headers: { 'Content-Type': 'application/json' }});463459 460 assert.response(app,461 { url: '/hello.haml' },462 { body: '%p Hello World'463 , status: 200, headers: { 'Content-Type': 'application/octet-stream' }});468464 465 assert.response(app,466 { url: '/doesNotExist' },467 { body: 'Cannot GET /doesNotExist', status: 404 });472468 469 assert.response(app,470 { url: '/partials' },471 { body: 'Cannot GET /partials', status: 404 });476472 473 assert.response(app,474 { url: '/large.json' },475 { status: 200, headers: { 'Content-Type': 'application/json' }});476 },
9 unmodified lines
486 if (err) return res.send('got an error');487 ++calls;488 });489 });494490 491 assert.response(app,492 { url: '/forum' },493 { body: 'got an error' });498494 495 assert.response(app,496 { url: '/does-not-exist' },497 { body: 'got an error' });502498 499 assert.response(app,500 { url: '/large.json' },501 { headers: { 'Accept-Ranges': 'bytes' }});506502 503 beforeExit(function(){504 calls.should.equal(1);505 });506 },
9 unmodified lines
516 if (err) return res.send('got an error');517 ++calls;518 });519 });524520 521 assert.response(app,522 { url: '/does-not-exist' },523 { body: 'got an error' });528524 525 assert.response(app,526 { url: '/large.json' },527 { headers: {528 'Accept-Ranges': 'bytes'529 , 'Cache-Control': 'public, max-age=3600'530 }});535531 532 beforeExit(function(){533 calls.should.equal(1);534 });535 },540 536 537 'test #sendfile() Accept-Ranges': function(){538 var app = express.createServer();539 540 app.get('/*', function(req, res, next){
59 unmodified lines
600 app.get('/json', function(req, res, next){601 var path = __dirname + '/fixtures/user.json';602 res.download(path, 'account.json');603 });608604 605 app.get('/callback', function(req, res, next){606 res.download(__dirname + '/fixtures/pets.json', function(err){607 ++calls;608 });609 });614610 611 app.get('/*', function(req, res, next){612 res.download(__dirname + '/fixtures/' + req.params[0]);613 });618614 615 assert.response(app,616 { url: '/callback' },617 { body: '["tobi", "loki", "jane"]' });622618 619 assert.response(app,620 { url: '/user.json' },621 { body: '{"name":"tj"}', status: 200, headers: {622 'Content-Type': 'application/json',
12 unmodified lines
635 { url: '/missing' },636 function(res){637 assert.equal(null, res.headers['content-disposition']);638 });643639 640 assert.response(app,641 { url: '/some%20random%20text%20file.txt' },642 { body: 'hello' });647643 644 beforeExit(function(){645 calls.should.equal(1);646 });647 },648 649 'test #cookie() path default': function(){650 var app = express.createServer();655651 652 app.set('home', '/foo');657653 654 app.get('/', function(req, res){655 res.cookie('rememberme', 'yes', { expires: new Date(1), httpOnly: true });656 res.cookie('something', 'else');657 res.redirect('/');658 });663659 660 assert.response(app,661 { url: '/', headers: { Host: 'foo.com' }},662 function(res){663 res.headers['set-cookie']664 .should.eql(['rememberme=yes; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/foo']);665 });666 },671667 668 'test #cookie() explicit path': function(){669 var app = express.createServer();674670 671 app.set('/home', '/foo');676672 673 app.get('/', function(req, res){674 res.cookie('rememberme', 'yes', { path: '/', expires: new Date(1), httpOnly: true });675 res.cookie('something', 'else');676 res.redirect('/');677 });682678 679 assert.response(app,680 { url: '/', headers: { Host: 'foo.com' }},681 function(res){682 res.headers['set-cookie']683 .should.eql(['rememberme=yes; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else; path=/']);684 });685 },690686 687 'test #cookie() null path': function(){688 var app = express.createServer();693689 690 app.set('/home', '/foo');695691 692 app.get('/', function(req, res){693 res.cookie('rememberme', 'yes', { path: null, expires: new Date(1), httpOnly: true });694 res.cookie('something', 'else', { path: null });695 res.redirect('/');696 });701697 698 assert.response(app,699 { url: '/', headers: { Host: 'foo.com' }},700 function(res){701 res.headers['set-cookie']702 .should.eql(['rememberme=yes; expires=Thu, 01 Jan 1970 00:00:00 GMT; httpOnly', 'something=else']);703 });704 },709705 706 'test #clearCookie() default path': function(){707 var app = express.createServer();712708 709 app.set('home', '/foo');714710 711 app.get('/', function(req, res){712 res.clearCookie('rememberme');713 res.redirect('/');714 });
4 unmodified lines
719 res.headers['set-cookie']720 .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);721 });722 },727723 724 'test #clearCookie() explicit path': function(){725 var app = express.createServer();730726 727 app.set('home', '/bar');732728 729 app.get('/', function(req, res){730 res.clearCookie('rememberme', { path: '/foo' });731 res.redirect('/');732 });
4 unmodified lines
737 res.headers['set-cookie']738 .should.eql(['rememberme=; path=/foo; expires=Thu, 01 Jan 1970 00:00:00 GMT']);739 });740 },745741 742 'test HEAD': function(){743 var app = express.createServer();744 745 app.get('/', function(req, res, next){
6 unmodified lines
752 },753 754 'test .charset with res.send()': function(){755 var app = express.createServer();760756 757 app.get('/', function(req, res){758 res.charset = 'ISO-8859-1';759 res.send('<p>hey</p>');760 });765761 762 assert.response(app,763 { url: '/' },764 { headers: { 'Content-Type': 'text/html; charset=ISO-8859-1' }});765 }
1 unmodified line
modified:test/router.test.js+55 added-55 removed
74 unmodified lines
75 },7677 'test precedence': function(){78 var app = express.createServer();7979 80 var hits = [];8181 82 app.all('*', function(req, res, next){83 hits.push('all');84 next();85 });8686 87 app.get('/foo', function(req, res, next){88 hits.push('GET /foo');89 next();90 });
1 unmodified line
92 app.get('/foo', function(req, res, next){93 hits.push('GET /foo2');94 next();95 });9696 97 app.put('/foo', function(req, res, next){98 hits.push('PUT /foo');99 next();100 });101101 102 assert.response(app,103 { url: '/foo' },104 function(){105 hits.should.eql(['all', 'GET /foo', 'GET /foo2']);106 });107 },108108 109 'test named capture groups': function(){110 var app = express.createServer();111111 112 app.get('/user/:id([0-9]{2,10})', function(req, res){113 res.send('user ' + req.params.id);114 });115115 116 app.post('/pin/save/:lat(\\d+.\\d+)/:long(\\d+.\\d+)', function(req, res){117 res.send(req.params.lat + ' ' + req.params.long);118 });119119 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 });123123 124 assert.response(app,125 { url: '/pin/save/1.2/3.4', method: 'POST' },126 { body: '1.2 3.4' });127127 128 assert.response(app,129 { url: '/pin/save2/1.2/3.4', method: 'POST' },130 { body: '1.2 3.4' });131131 132 assert.response(app,133 { url: '/user/12' },134 { body: 'user 12' });135
3 unmodified lines
139 },140 141 'test app.param()': function(){142 var app = express.createServer();143143 144 var users = [145 { name: 'tj' }146 , { name: 'tobi' }147 , { name: 'loki' }148 , { name: 'jane' }149 , { name: 'bandit' }150 ];151151 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 });159159 160 app.get('/user/:user', function(req, res, next){161 res.send('user ' + req.user.name);162 });163163 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 },172172 173 'test app.param() optional execution': function(beforeExit){174 var app = express.createServer()175 , calls = 0;176176 177 var months = ['Jan', 'Feb', 'Mar'];178178 179 app.param('month', function(req, res, next, n){180 req.params.month = months[n];181 ++calls;182 next();183 });184184 185 app.get('/calendar/:month?', function(req, res, next){186 res.send(req.params.month || months[0]);187 });188188 189 assert.response(app,190 { url: '/calendar' },191 { body: 'Jan' });192192 193 assert.response(app,194 { url: '/calendar/1' },195 { body: 'Feb' });196196 197 beforeExit(function(){198 calls.should.equal(1);199 });200 },
20 unmodified lines
221 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(){});225225 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 }]);233233 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);241241 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 line
247 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 },251251 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(){});257257 258 app.get('/user').should.have.length(2);259 var removed = app.remove.get('/user');260 removed.should.have.length(2);261261 262 var removed = app.remove.get('/user');263 removed.should.have.length(0);264 app.get('/user').should.have.length(0);265265 266 app.get('/user/:id', function(){});267 app.put('/user/:id', function(){});268 app.del('/user/:id', function(){});269269 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(){});276276 277 app.remove('/user/:id').should.have.length(3);278 },279 280 'test app.match': function(){
2 unmodified lines
283 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(){});287287 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');296296 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 line
302 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 },306306 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(){});314314 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 },320320 321 'test "strict routing" setting': function(){322 var app = express.createServer();323323 324 app.enable('strict routing');325325 326 app.get('/:path', function(req, res, next){327 res.send({ type: 'directory' });328 });329329 330 app.get('/:path/', function(req, res, next){331 res.send(['.', '..', 'foo.js', 'bar.js']);332 });333333 334 assert.response(app,335 { url: '/lib' },336 { body: '{"type":"directory"}' });337337 338 assert.response(app,339 { url: '/lib/' },340 { body: '[".","..","foo.js","bar.js"]' });341 },342342 343 'test "case sensitive routes" setting': function(){344 var app = express.createServer();345345 346 app.enable('case sensitive routes');347347 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 });355355 356 assert.response(app,357 { url: '/account' },358 { body: 'account' });359359 360 assert.response(app,361 { url: '/Account' },362 { body: 'Account' });363 },364 365 'override OPTIONS default': function(){366 var app = express.createServer();367367 368 app.get('/', function(req, res, next){369 370 });371371 372 app.options('/foo', function(req, res, next){373 res.header('Allow', 'GET')374 res.send('whatever');375 });376376 377 assert.response(app,378 { url: '/', method: 'OPTIONS' },379 { body: 'GET', headers: { Allow: 'GET' }});380380 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();388388 389 var routes = [];390390 391 app.get('/:foo?', function(req, res, next){392 routes.push(req.route.path);393 next();394 });395395 396 app.get('/foo', function(req, res, next){397 routes.push(req.route.path);398 next();399 });400400 401 assert.response(app,402 { url: '/foo' },403 function(){404 routes.should.eql(['/:foo?', '/foo']);
3 unmodified lines