Skip to content
Myr

Added `req.get()` alias of `req.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 bfba98f · Browse files · 2 files+21 added−9 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+21 added−9 removed

  • tests:+9 added−0 removed
  • other:+12 added−9 removed

2 files+21 added−9 removed

modified:lib/request.js+12 added-9 removed
31 unmodified lines
32 *33 * Examples:34 *35 * req.header('Content-Type');36 * req.get('Content-Type');37 * // => "text/plain"38 * 39 * req.header('content-type');40 * req.get('content-type');41 * // => "text/plain"42 * 43 * req.header('Something');44 * // => undefined
2 unmodified lines
47 * @return {String} 48 * @api public49 */5049req.header = function(name){51req.header = 52req.get = function(name){53 switch (name = name.toLowerCase()) {54 case 'referer':55 case 'referrer':56 return this.headers.referrer
19 unmodified lines
76 * @return {String}77 * @api public78 */7977req.get = function(field, param){78 // TODO: rename... add tests, make .get() .header()79 var val = this.header(field);80 if (!val) return '';81 var regexp = new RegExp(param + ' *= *(?:"([^"]+)"|([^;]+))', 'i');82 if (!regexp.exec(val)) return '';83 return RegExp.$1 || RegExp.$2;84};80// req.get = function(field, param){81// // TODO: rename... add tests, make .get() .header()82// var val = this.header(field);83// if (!val) return '';84// var regexp = new RegExp(param + ' *= *(?:"([^"]+)"|([^;]+))', 'i');85// if (!regexp.exec(val)) return '';86// return RegExp.$1 || RegExp.$2;87// };8889/**90 * Check if the given `type` is acceptable,91 * otherwise you should respond with 406 "Not Acceptable".
295 unmodified lines
modified:test/req.header.js+9 added