Styling
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent f7d7c4a · Browse files · 1 file·+38 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+38 added−39 removed
- other:+38 added−39 removed
Provenance
- Commit
0f74408- Tree
0444cb7- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
f7d7c4a
1 file changed+38 added−39 removed
modified:lib/express/core.js+38 added-39 removed
207 unmodified lines208 require('http')209 .createServer(function(request, response){210 request.body = ''211 request.setBodyEncoding('binary')212- var callback= function(error, result) {213- if(error) { // THIS is the same code as in the 'route' code, needs refactoring214- if (request.accepts('html') && set('show exceptions'))215- request.halt(500, require('express/pages/show-exceptions').render(request, error))216- else217- request.halt(500)218- if (set('throw exceptions'))219- throw error220- } 221- else self.route(request, response); 222- };212+ function callback(e, result) {213+ if (!e) return self.route(request, response)214+ // TODO: refactore -- same code used in #route(); make util215+ if (request.accepts('html') && set('show exceptions'))216+ request.halt(500, require('express/pages/show-exceptions').render(request, e))217+ else218+ request.halt(500)219+ if (set('throw exceptions'))220+ throw error221+ else self.route(request, response) 222+ }223 if (request.headers['content-type'] &&224 request.headers['content-type'].indexOf('multipart/form-data') !== -1) {225- var mp= multipart.parse(request);226- request.params= { post: {}};227- mp.addListener("partBegin", function (part) { 228- if( part.filename ) {229- part.tempfile= '/tmp/express-' + Number(new Date) + utils.uid(); 230- part.fileStream= fs.createWriteStream( part.tempfile ); 231- }232- else part.buf= '';233- });234- mp.addListener("partEnd", function (part) { 235- if( part.name ) { // Not sure why this guard is needed, but otherwise we get an undefined part.name being passed?236- if( part.fileStream ) { 237- part.fileStream.close(); 238- utils.mergeParam(part.name, {filename:part.filename, tempfile:part.tempfile}, request.params.post) 239- }240- else {241- utils.mergeParam(part.name, part.buf, request.params.post) 242- }243- }244- });245- 246- mp.addListener("body", function (chunk) {247- if( mp.part.fileStream ) mp.part.fileStream.write(chunk) ;248- else part.buf+= chunk;249- });250- mp.addListener("error", callback); 251- mp.addListener("complete", callback);225+ var mp= multipart.parse(request)226+ request.params= { post: {}}227+ mp.addListener("partBegin", function (part) { 228+ if (part.filename) {229+ part.tempfile = '/tmp/express-' + Number(new Date) + utils.uid()230+ part.fileStream = fs.createWriteStream( part.tempfile )231+ }232+ else part.buf = ''233+ })234+ mp.addListener("partEnd", function(part) { 235+ if (part.name) { // Not sure why this guard is needed, but otherwise we get an undefined part.name being passed?236+ if (part.fileStream) { 237+ part.fileStream.close(); 238+ utils.mergeParam(part.name, { filename:part.filename, tempfile:part.tempfile }, request.params.post) 239+ }240+ else241+ utils.mergeParam(part.name, part.buf, request.params.post) 242+ }243+ });244+ 245+ mp.addListener("body", function(chunk) {246+ if (mp.part.fileStream) mp.part.fileStream.write(chunk)247+ else part.buf += chunk248+ });249+ mp.addListener("error", callback)250+ mp.addListener("complete", callback)251 }252 else253 request254 .addListener('data', function(chunk){ request.body += chunk })256- .addListener('end', callback )255+ .addListener('end', callback)256 })257 .listen(this.port, this.host, this.backlog)258 puts('Express started at http://' + this.host + ':' + this.port + '/ in ' + Express.environment + ' mode')259 },63 unmodified lines