Skip to content
Myr

Fixed bug producing messed up response bodies

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

Express was trying to respond twice to the same request due to an error caused by having no callback, which was then caught, and responded to using Request#error() haha!

authored by visionmedia · committed by visionmedia · parent 0dba9bd · Browse files · 2 files+15 added−8 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−8 removed

  • other:+15 added−8 removed

2 files+15 added−8 removed

modified:lib/express/core.js+3 added-5 removed
274 unmodified lines
275 276 route: function(request){ 277 var self = this278 request.trigger('request', function(err) {279 try {279 try { 280 if (err) throw err281 if (request.response.finished) return282 if (typeof (body = (new Router(request)).route()) === 'string')283 request.respond(200, body, function(err){284 if (err) request.error(err)285 })283 request.respond(200, body)284 } catch (err) {285 request.error(err)288 } 286 }287 })288 }289})290
35 unmodified lines
modified:lib/express/request.js+12 added-3 removed
157 unmodified lines
158 * The status _code_ defaults to to 404, and _body_ will159 * default to the default body associated with the response160 * _code_.161 *162 * The _callback_ may be given as the 3rd or 4th argument,163 * which is then called when an error occurs OR when the response164 * has been completed.165 *166 * Examples:167 *168 * request.respond()169 * // 404 "Not Found"
8 unmodified lines
178 * // "utf8" will set Request#charset to 'UTF-8'179 *180 * @param {int} code181 * @param {string} body178 * @param {string} encoding182 * @param {string|function} encoding183 * @param {function} callback184 * @see statusBodies185 * @api public186 */187183 respond: function(code, body, encoding) {188 respond: function(code, body, encoding, callback) {189 var self = this190 this.status(code = code || 404)191 if (encoding instanceof Function)192 callback = encoding,193 encoding = null194 if (body !== null)195 body = body || statusBodies[code]196 if (encoding === 'utf8' ||197 encoding === 'utf-8')198 this.charset = 'UTF-8'199 this.response.body = body200 this.trigger('response', function(err) {193 if (err) return self.error(err)201 if (err) return self.error(err, callback)202 self.sendHead()203 if (body) self.response.write(self.response.body, encoding)204 self.response.end()205 if (callback) callback()206 }, true)207 },208 209 // >>> DEPRECATED: remove in 1.0
228 unmodified lines