Added BodyDecoder plugin, required by core
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 57f8e82 · Browse files · 7 files·+43 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+43 added−32 removed
- tests:+27 added−24 removed
- other:+16 added−8 removed
Provenance
- Commit
251c027- Tree
7f6d724- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
57f8e82
7 files changed+43 added−32 removed
added:lib/express/plugins/body-decoder.js+15 added
123456789101112131415
// Express - BodyDecoder - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
exports.BodyDecoder = Plugin.extend({ on: { request: function(event) { var request = event.request request.uri.post = request.header('content-type') && request.header('content-type').indexOf('application/x-www-form-urlencoded') > -1 ? parseParams(request.body) : {} } }})No newline at end of filemodified:lib/express/plugins/redirect.js-4 removed
30 unmodified lines3132333435363738353637386 unmodified lines30 unmodified lines this.halt(code || 303) } })
// --- Expose
process.mixin(GLOBAL, exports)
// --- Redirect
exports.Redirect = Plugin.extend({ on: {6 unmodified linesmodified:lib/express/core.js+1 added
255 unmodified lines256 // --- Defaults257 258 configure(function(){259 set('views', function(){ return set('root') + '/views' })260+ use(require('express/plugins/body-decoder').BodyDecoder)261 })262 263 configure('test', function(){264 enable('throw exceptions')1 unmodified linemodified:lib/express/request.js-4 removed
98 unmodified lines99 this.uri.params = parseNestedParams(this.uri.params)100 this.plugins = $(Express.plugins).map(function(plugin){101 return new plugin.klass(plugin.options) 102 })103- this.uri.post = 104- this.header('content-type') && this.header('content-type').indexOf('application/x-www-form-urlencoded') > -1 ?105- parseParams(this.body) :106- {}103 },104 105 /**106 * Set response header _key_ and _val_ or get129 unmodified linesmodified:spec/spec.node.js+1 added
32 unmodified lines3334353637383940414232 unmodified lines .exec('spec/spec.plugins.js') .exec('spec/spec.plugins.common-logger.js') .exec('spec/spec.plugins.content-length.js') .exec('spec/spec.plugins.method-override.js') .exec('spec/spec.plugins.body-decoder.js') .exec('spec/spec.plugins.redirect.js') .exec('spec/spec.plugins.hooks.js') .exec('spec/spec.plugins.cookie.js')JSpec.run({ formatter: JSpec.formatters.Terminal, failuresOnly: true })JSpec.report()added:spec/spec.plugins.body-decoder.js+26 added
1234567891011121314151617181920212223242526
describe 'Express' describe 'BodyDecoder' describe 'given "application/x-www-form-urlencoded"' it 'should parse body as urlencoded params' post('/login', function(){ return this.param('name') }) var response = post('/login', { body: 'name=tj', headers: { 'content-type': 'application/x-www-form-urlencoded' }}) response.status.should.eql 200 response.body.should.eql 'tj' end describe 'with charset' it 'should parse body as urlencoded params' post('/login', function(){ return this.param('name') }) var response = post('/login', { body: 'name=tj', headers: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }}) response.status.should.eql 200 response.body.should.eql 'tj' end end end endendNo newline at end of filemodified:spec/spec.request.js-24 removed
2 unmodified lines3 before_each4 reset()5 end6 7- describe '#init()'8- describe 'when content-type is "application/x-www-form-urlencoded"'9- it 'should parse body as urlencoded params'10- post('/login', function(){11- return this.param('name')12- })13- var response = post('/login', { body: 'name=tj', headers: { 'content-type': 'application/x-www-form-urlencoded' }})14- response.status.should.eql 20015- response.body.should.eql 'tj'16- end17- 18- describe 'with charset'19- it 'should parse body as urlencoded params'20- post('/login', function(){21- return this.param('name')22- })23- var response = post('/login', { body: 'name=tj', headers: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }})24- response.status.should.eql 20025- response.body.should.eql 'tj'26- end27- end28- end29- end30-7 describe 'status()'8 it 'should set the response status'9 get('/user', function(){ this.status(500) })10 get('/user').status.should.eql 500141 unmodified lines