Recent node no longer uses arrays for hashes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent f623873 · Browse files · 2 files·+6 added−53 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+6 added−53 removed
- tests:+5 added−19 removed
- other:+1 added−34 removed
Provenance
- Commit
ab92400- Tree
89853fa- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
f623873
2 files changed+6 added−53 removed
modified:lib/express.core.js+1 added-34 removed
249 unmodified lines250 Express.response.body = null251 Express.response.status = 200252 Express.request = request253 Express.originalResponse = response254- request.headers = Express.arrayToHash(request.headers)254 request.uri.params = Express.parseNestedParams(request.uri.params)255 request.uri.path = Express.normalizePath(request.uri.path)256 Express.hook('onRequest')257 try { Express.response.body = Express.callRouteFor(request) }6 unmodified lines264 265 finished: function(body) {266 if (body) Express.response.body = body267 Express.hook('onResponse')269- Express.originalResponse.sendHeader(Express.response.status, Express.hashToArray(Express.response.headers))268+ Express.originalResponse.sendHeader(Express.response.status, Express.response.headers)269 Express.originalResponse.sendBody(Express.response.body || '')270 Express.originalResponse.finish()271 }272 },13 unmodified lines286 this.response.status = 500287 },288 289 /**291- * Return an associative array generated292- * from the key / value pairs in _hash_.293- *294- * @param {hash} hash295- * @return {array}296- * @api public297- */298- 299- hashToArray : function(hash) {300- var array = []301- for (var key in hash)302- array.push([key, hash[key]])303- return array304- },305- 306- /**307- * Return hash generated from an308- * associative array.309- *310- * @param {array} array311- * @return {hash}312- * @api public313- */314- 315- arrayToHash : function(array) {316- var hash = {}317- for (var i = 0, len = array.length; i < len; ++i)318- hash[array[i][0].toLowerCase()] = array[i][1]319- return hash320- },321- 322- /**290 * JSON encode _object_291 *292 * @param {mixed} object293 * @return {string}402 unmodified linesmodified:spec/spec.core.js+5 added-19 removed
131 unmodified lines132 Express.response.status.should.eql 404133 Express.response.body.should.eql 'File cannot be found'134 end135 end136- 137- describe '.hashToArray()'138- it 'should map hash key / value pairs to an array'139- headers = { 'Content-Type' : 'text/plain' }140- Express.hashToArray(headers).should.eql [['Content-Type', 'text/plain']]141- end142- end143- 144- describe '.arrayToHash()'145- it 'should map an assoc array to an object'146- headers = [['Content-Type', 'text/plain']]147- Express.arrayToHash(headers).should.eql { 'content-type' : 'text/plain' }148- end149- end150- 136+137 describe '.redirect()'138 it 'should redirect to the url specified'139 get('foo', function(){ redirect('http://google.com') })140 response = get('foo')22 unmodified lines163 describe '.back'164 it 'should redirect to the referrer'165 uri = 'http://vision-media.ca'166 get('foo', function(){ redirect(back) })181- request = mockRequest({ headers : [['Referer', uri]] })167+ request = mockRequest({ headers : { 'Referer': uri }})168 get('foo', { request: request }).headers.location.should.eql uri169 Express.back.should.eql uri170 end171 end2 unmodified lines174 describe 'BodyDecoder'175 it 'should parse urlencoded bodies'176 request = mockRequest({177 method: 'POST',192- headers : [['Content-Type', 'application/x-www-form-urlencoded']],178+ headers : { 'content-type': 'application/x-www-form-urlencoded' },179 body : 'user[name]=foo%20bar&status=1'180 })181 post('admin', function(){ param('user').name + ' ' + param('status') })182 post('admin', { request : request }).body.should.eql 'foo bar 1'1 unmodified line184 185 it 'should parse JSON bodies'186 request = mockRequest({187 method: 'POST',202- headers : [['Content-Type', 'application/json']],188+ headers : { 'content-type': 'application/json' },189 body : '{ foo : "bar" }'190 })191 post('foo', function(){ param('foo') })192 post('foo', { request : request }).body.should.eql 'bar'10 unmodified lines203 describe 'MethodOverride'204 it 'should override request method when _method param is present'205 request = mockRequest({206 method: 'POST',221- headers : [['Content-Type', 'application/x-www-form-urlencoded']],207+ headers : { 'content-type': 'application/x-www-form-urlencoded' },208 body : '_method=delete'209 })210 del('foo', function(){ 'Deleted' })211 post('foo', { request : request}).body.should.eql 'Deleted'15 unmodified lines