Header fields case insensitive
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 1da8234 · Browse files · 2 files·+15 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
2 files+15 added−4 removed
- tests:+11 added−1 removed
- other:+4 added−3 removed
Provenance
- Commit
6dc1715- Tree
2eb4694- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
1da8234
2 files changed+15 added−4 removed
modified:lib/express.core.js+4 added-3 removed
185 unmodified lines186 187 arrayToHash : function(array) {188 var hash = {}189 for (i = 0, len = array.length; i < len; ++i)190- hash[array[i][0]] = array[i][1]190+ hash[array[i][0].toLowerCase()] = array[i][1]191 return hash192 },193 194 /**47 unmodified lines242 if (typeof value == 'number') return this.response.status = value243 for (var code in node.http.STATUS_CODES)244 if (node.http.STATUS_CODES.hasOwnProperty(code))245 if (node.http.STATUS_CODES[code].toLowerCase() == value.toLowerCase())246- return this.response.status = code246+ return this.response.status = parseInt(code)247 },248 249 /**250 * Set response _status_ and _body_.18 unmodified lines269 * @api public270 */271 272 header : function(name, value) {273+ name = name.toLowerCase()274 return value ? this.response.headers[name] = value :275 this.request.headers[name] || this.response.headers[name]276 },277 199 unmodified lines477 if (!route.options.provides) return true478 if (route.options.provides.constructor != Array) 479 route.options.provides = [route.options.provides]480 for (i = 0, len = route.options.provides.length; i < len; ++i)480- if (request.headers['Accept'].match(route.options.provides[i]))481+ if (request.headers.accept.match(route.options.provides[i]))482 return true483 return false484 },485 100 unmodified linesmodified:spec/spec.core.js+11 added-1 removed
78 unmodified lines798081828383848586878889909160 unmodified lines15215315415515615715815916016116216316416578 unmodified lines describe '.header()' it 'should set / get headers' Express.request = {} Express.request.headers = { 'Accept' : 'text/plain' } Express.request.headers = { 'accept' : 'text/plain' } Express.header('Content-Type', 'text/html') Express.header('Content-Type').should.eql 'text/html' Express.header('Accept').should.eql 'text/plain' Express.header('accept').should.eql 'text/plain' end end describe '.status()'60 unmodified lines one.should.eql [1, 2] two.should.be_true end end describe '.redirect()' it 'should redirect to the url specified' get('foo', function(){ redirect('http://google.com') }) response = get('foo') response.headers.location.should.eql 'http://google.com' response.status.should.eql 302 end endend