Skip to content
Myr

Added Request#isXHR. Closes #229

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

Merge branch 'integration'

authored by visionmedia · committed by visionmedia · parents 088aa83, 3b9921a · Browse files · 3 files+32 added−4 removed
This commit

State

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

Diff stats

3 files+32 added−4 removed

  • tests:+17 added−0 removed
  • other:+15 added−4 removed

3 files+32 added−4 removed

modified:lib/express/request.js+14 added-3 removed
70 unmodified lines
71 */7273 header: function(key, val) {74 return val === undefined75 ? this.headers[key.toLowerCase()]76 : this.response.headers[key.toLowerCase()] = val75 ? this.headers[key.lowercase]76 : this.response.headers[key.lowercase] = val77 },78 79 /**80 * Return a param _key_ value or null.
41 unmodified lines
122 accept.indexOf(type.split('/')[0]+'/*') !== -1123 })124 : true125 },126 127 /**128 * Check if the request was an xmlHttpRequest (ajax).129 *130 * @return {bool}131 * @api public132 */133134 get isXHR() {135 return (this.header('x-requested-with') || '').lowercase === 'xmlhttprequest'136 },137138 /**139 * Set response status to _code_.140 *141 * @param {int} code131 * @return {Request)142 * @return {Request}143 * @api public144 */145146 status: function(code) {
152 unmodified lines
modified:spec/spec.request.js+17 added
37 unmodified lines
38 end39 end40 end41 42 describe '#isXHR'43 it 'should return false unless X-Requested-With is "XMLHttpRequest"'44 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })45 get('/').body.should.eql 'nope'46 end47 48 it 'should return true when X-Requested-With is "XMLHttpRequest"'49 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })50 get('/', { headers: { 'x-requested-with': 'XMLHttpRequest' }}).body.should.eql 'yay'51 end52 53 it 'should be case insensitive'54 get('/', function(){ return this.isXHR ? 'yay' : 'nope' })55 get('/', { headers: { 'x-requested-with': 'xmlhttprequest' }}).body.should.eql 'yay'56 end57 end58 59 describe '#accepts()'60 describe 'when the Accept header is present'61 it 'should return true if the mime type is acceptable'62 get('/user', function(){ return this.accepts('jpeg').toString() })
185 unmodified lines
modified:Readme.md+1 added-1 removed