Skip to content
Myr

Merge branch 'param'

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 943e9b3, 4d96479 · Browse files · 2 files+53 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+53 added−0 removed

  • tests:+31 added−0 removed
  • other:+22 added−0 removed

2 files+53 added−0 removed

modified:lib/request.js+22 added
64 unmodified lines
65 }66};6768/**69 * Get `field`'s `param` value, defaulting to ''.70 *71 * Examples:72 *73 * req.get('content-disposition', 'filename');74 * // => "something.png"75 *76 * @param {String} field77 * @param {String} param78 * @return {String}79 * @api public80 */8182req.get = function(field, param){83 var val = this.header(field);84 if (!val) return '';85 var regexp = new RegExp(key + ' *= *(?:"([^"]+)"|([^;]+))', 'i');86 if (!regexp.exec(val)) return '';87 return RegExp.$1 || RegExp.$2;88};8990/**91 * Check if the _Accept_ header is present, and includes the given `type`.92 *93 * When the _Accept_ header is not present `true` is returned. Otherwise94 * the given `type` is matched by an exact match, and then subtypes. You
215 unmodified lines
modified:test/request.test.js+31 added
301 unmodified lines
302303 assert.response(app,304 { url: '/incorrect', headers: { Referer: 'expressjs.com' }},305 { body: 'expressjs.com' });306 },307 308 'test #get(field, param)': function(){309 var app = express.createServer();310311 app.get('/', function(req, res, next){312 req.get('content-disposition', 'filename')313 .should.equal('foo bar.jpg');314315 req.get('Content-Disposition', 'filename')316 .should.equal('foo bar.jpg');317318 req.get('x-content-foo', 'foo').should.equal('bar');319 req.get('x-content-foo', 'bar').should.equal('foo bar baz');320 req.get('x-content-foo', 'woot').should.equal('tobi loki jane');321 req.get('cache-control', 'max-age').should.equal('500');322323 req.get('foo').should.equal('');324 req.get('foo', 'bar').should.equal('');325 res.end();326 });327328 var fields = {329 'Content-Disposition': 'attachment; filename="foo bar.jpg"'330 , 'X-Content-Foo': 'foo=bar; bar=foo bar baz; woot=tobi loki jane;'331 , 'Cache-Control': 'max-age = 500'332 };333334 assert.response(app,335 { url: '/', headers: fields },336 { body: '' });337 }338};