Skip to content
Myr

Request instance created before body parsing. Closes #262

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

Merge branch 'request'

authored by visionmedia · committed by visionmedia · parents 62b9a9e, d3dedd6 · Browse files · 4 files+22 added−26 removed
This commit

State

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

Diff stats

4 files+22 added−26 removed

  • tests:+4 added−4 removed
  • other:+18 added−22 removed

4 files+22 added−26 removed

modified:examples/chat/app.js+1 added-1 removed
modified:lib/express/spec/mocks.js+4 added-4 removed
125 unmodified lines
126 * @api private127 */128129function request(method, path, options, callback) {130 var response = new MockResponse131 var request = new MockRequest(method, path, options)132 Express.server.route(request, response)133 return response130 var req = new MockRequest(method, path, options),131 res = new MockResponse132 Express.server.route(new Request(req, res))133 return res134}135136/**137 * Request Express data which may have been
40 unmodified lines
modified:lib/express/core.js+15 added-19 removed
213 unmodified lines
214 if (host !== undefined) this.host = host215 if (port !== undefined) this.port = port216 if (backlog !== undefined) this.backlog = backlog217 require('http')218 .createServer(function(request, response){218 .createServer(function(req, response){219 var request, pendingFiles = 0220 req.setBodyEncoding('binary')221 request = new Request(req, response)222 request.body = ''220 request.setBodyEncoding('binary')223 function callback(err) {222 if (!(request instanceof Request))223 request = new Request(request, response)224 if (err)225 request.error(err)226 else if (!pendingFiles)227 self.route(request, response)227 self.route(request)228 }229 if (request.headers['content-type'] &&230 request.headers['content-type'].includes('multipart/form-data')) {231 var stream = multipart.parse(request),232 contentLength = parseInt(request.headers['content-length']),233 maxBodyLength = set('max upload size'),234 pendingFiles = 0229 if (request.header('content-type') &&230 request.header('content-type').includes('multipart/form-data')) {231 var stream = multipart.parse(req),232 contentLength = parseInt(request.header('content-length')),233 maxBodyLength = set('max upload size')234 if (maxBodyLength && contentLength > maxBodyLength)235 return callback(new Error('upload size limit exceeded'))237 request.params = { post: {}}236 stream237 .addListener('partBegin', function(part) {238 if (part.filename)239 ++pendingFiles,
23 unmodified lines
263 .addListener('error', callback)264 .addListener('complete', callback)265 }266 else269 request267 req268 .addListener('data', function(chunk){ request.body += chunk })269 .addListener('end', callback)270 })271 .listen(this.port, this.host, this.backlog)272 puts('Express started at http://' + this.host + ':' + this.port + '/ in ' + Express.environment + ' mode')273 },274 275 /**278 * Route the given _request_ and _response_.276 * Route the given _request_.277 *280 * @param {object} request281 * @param {object} response278 * @param {Request} request279 * @api private280 */281 285 route: function(request, response){ 286 var self = this,287 request = new Request(request, response)282 route: function(request){ 283 var self = this284 request.trigger('request', function(err) {285 try {286 if (err) throw err287 if (request.response.finished) return
46 unmodified lines
modified:lib/express/request.js+2 added-2 removed
49 unmodified lines
50 response.headers = {}51 this.response = response 52 this.url = url.parse(this.url)53 this.url.pathname = exports.normalizePath(this.url.pathname) 54 this.params = this.params || {}55 this.params.path = {}54 this.params = {}55 this.params.path = {}56 this.params.get = this.url.query ? queryString.parseQuery(this.url.query) : {}57 this.params.post = this.params.post || {}58 this.plugins = Express.plugins.map(function(plugin){59 return new plugin.klass(plugin.options)
299 unmodified lines