Skip to content
Myr

Added Request#isXHR specs

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

authored by visionmedia · committed by visionmedia · parent 6a8781b · Browse files · 2 files+20 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

2 files+20 added−3 removed

  • tests:+17 added−0 removed
  • other:+3 added−3 removed

2 files+20 added−3 removed

modified:lib/express/request.js+3 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.
50 unmodified lines
131 * @api public132 */133134 get isXHR() {135 return (this.header('X-Requested-With') || '').toLowerCase() === 'xmlhttprequest'135 return (this.header('x-requested-with') || '').lowercase === 'xmlhttprequest'136 },137138 /**139 * Set response status to _code_.
159 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