Skip to content
Myr

2 spaces in request.js

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 5152823 · Browse files · 2 files+59 added−59 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+59 added−59 removed

  • other:+59 added−59 removed

2 files+59 added−59 removed

modified:lib/express/index.js+1 added-1 removed
modified:lib/express/request.js+58 added-58 removed
7 unmodified lines
8/**9 * Module dependencies.10 */1112var http = require('http'),13 utils = require('./utils'),14 mime = require('connect/utils').mime;12var http = require('http')13 , utils = require('./utils')14 , mime = require('connect/utils').mime;1516/**17 * Default flash formatters.18 *19 * @type Object20 */2122var flashFormatters = exports.flashFormatters = {23 s: function(val){24 return String(val);25 }23 s: function(val){24 return String(val);25 }26};2728/**29 * Return request header or optional default.
18 unmodified lines
48 * @api public49 */5051http.IncomingMessage.prototype.header = function(name, defaultValue){52 return this.headers[name.toLowerCase()] || defaultValue;52 return this.headers[name.toLowerCase()] || defaultValue;53};5455/**56 * Check if the _Accept_ header is present, and includes the given `type`.
25 unmodified lines
82 * @api public83 */8485http.IncomingMessage.prototype.accepts = function(type){86 var accept = this.header('Accept');87 if (!accept || accept === '*/*') {88 return true;89 } else if (type) {90 // Allow "html" vs "text/html" etc91 if (type.indexOf('/') < 0) {92 type = mime.types['.' + type];93 }94 // Check if we have a direct match95 if (accept.indexOf(type) >= 0) {96 return true;97 // Check if we have type/*98 } else {99 type = type.split('/')[0] + '/*';100 return accept.indexOf(type) >= 0;101 }86 var accept = this.header('Accept');87 if (!accept || accept === '*/*') {88 return true;89 } else if (type) {90 // Allow "html" vs "text/html" etc91 if (type.indexOf('/') < 0) {92 type = mime.types['.' + type];93 }94 // Check if we have a direct match95 if (accept.indexOf(type) >= 0) {96 return true;97 // Check if we have type/*98 } else {103 return false;99 type = type.split('/')[0] + '/*';100 return accept.indexOf(type) >= 0;101 }102 } else {103 return false;104 }105};106107/**108 * Return the value of param `name` when present.
11 unmodified lines
120 * @api public121 */122123http.IncomingMessage.prototype.param = function(name){124 // Route params like /user/:id125 if (this.params[name] !== undefined) {126 return this.params[name]; 127 }128 // Query string params129 if (this.query[name] !== undefined) {130 return this.query[name]; 131 }132 // Request body params via connect.bodyDecoder133 if (this.body && this.body[name] !== undefined) {134 return this.body[name];135 }124 // Route params like /user/:id125 if (this.params[name] !== undefined) {126 return this.params[name]; 127 }128 // Query string params129 if (this.query[name] !== undefined) {130 return this.query[name]; 131 }132 // Request body params via connect.bodyDecoder133 if (this.body && this.body[name] !== undefined) {134 return this.body[name];135 }136};137138/**139 * Queue flash `msg` of the given `type`.
30 unmodified lines
170 * @api public171 */172173http.IncomingMessage.prototype.flash = function(type, msg){174 var msgs = this.session.flash = this.session.flash || {};175 if (type && msg) {176 var i = 2,177 args = arguments,178 formatters = this.app.flashFormatters || {};179 formatters.__proto__ = flashFormatters;180 msg = utils.miniMarkdown(utils.htmlEscape(msg));181 msg = msg.replace(/%([a-zA-Z])/g, function(_, format){182 var formatter = formatters[format];183 if (formatter) return formatter(args[i++]);184 });185 return (msgs[type] = msgs[type] || []).push(msg);186 } else if (type) {187 var arr = msgs[type];188 delete msgs[type];189 return arr || [];190 } else {191 this.session.flash = {};192 return msgs;193 }174 var msgs = this.session.flash = this.session.flash || {};175 if (type && msg) {176 var i = 2177 , args = arguments178 , formatters = this.app.flashFormatters || {};179 formatters.__proto__ = flashFormatters;180 msg = utils.miniMarkdown(utils.htmlEscape(msg));181 msg = msg.replace(/%([a-zA-Z])/g, function(_, format){182 var formatter = formatters[format];183 if (formatter) return formatter(args[i++]);184 });185 return (msgs[type] = msgs[type] || []).push(msg);186 } else if (type) {187 var arr = msgs[type];188 delete msgs[type];189 return arr || [];190 } else {191 this.session.flash = {};192 return msgs;193 }194};195196// Callback for isXMLHttpRequest / xhr197198function isxhr() {199 return this.header('X-Requested-With', '').toLowerCase() === 'xmlhttprequest';199 return this.header('X-Requested-With', '').toLowerCase() === 'xmlhttprequest';200}201202/**203 * Check if the request was an _XMLHttpRequest_.
2 unmodified lines
206 * @api public207 */208209http.IncomingMessage.prototype.__defineGetter__('isXMLHttpRequest', isxhr);210http.IncomingMessage.prototype.__defineGetter__('xhr', isxhr);210http.IncomingMessage.prototype.__defineGetter__('xhr', isxhr);