Skip to content
Myr

Implemented req.is()

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 9da2adf · Browse files · 1 file+32 added−3 removed
This commit

State

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

Diff stats

1 file+32 added−3 removed

  • other:+32 added−3 removed

1 file+32 added−3 removed

modified:lib/express/request.js+32 added-3 removed
191 unmodified lines
192 return msgs;193 }194};195196/**197 * Check if the incoming request contains the "Content-Type" 198 * header field, and it contains the give mime `type`.199 *200 * Examples:201 *202 * // With Content-Type: text/html; charset=utf-8203 * req.is('html');204 * // => true205 *206 * req.is('text/html');207 * // => true208 *209 * // When Content-Type is application/json210 * req.is('json');211 * // => true212 *213 * req.is('application/json');214 * // => true215 *216 * req.is('html');217 * // => false218 *219 * @param {String} type220 * @return {Boolean}221 * @api public222 */223224http.IncomingMessage.prototype.is = function(type){225 var contentType = this.headers['content-type'];226 if (!contentType) return;199 if (!type.indexOf('/')) type = mime.type('.' + type);200 return contentType.indexOf(type);227 if (!~type.indexOf('/')) type = mime.type('.' + type);228 // TODO: remove when connect no longer appends charset...229 if (~type.indexOf(';')) type = type.split(';')[0];230 return ~contentType.indexOf(type);231};232203233// Callback for isXMLHttpRequest / xhr234235function isxhr() {236 return this.header('X-Requested-With', '').toLowerCase() === 'xmlhttprequest';
11 unmodified lines