Skip to content
Myr

Added encoding param to Request#halt() and Request#respond()

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

authored by visionmedia · committed by visionmedia · parent b1a2b7b · Browse files · 3 files+11 added−10 removed
This commit

State

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

Diff stats

3 files+11 added−10 removed

  • other:+11 added−10 removed

3 files+11 added−10 removed

modified:lib/express/request.js+9 added-8 removed
169 unmodified lines
170 return this.response.status = code171 },172 173 /**174 * Immediately respond with response _code_ and _body_.174 * Immediately respond with response _code_, _body_ and optional _encoding_.175 * The status _code_ defaults to to 404, and _body_ will176 * default to the default body associated with the response177 * _code_.178 *
1 unmodified line
180 * will be thrown.181 *182 * @param {int} code183 * @param {string} body184 * @param {string} encoding185 * @see statusBodies186 * @api public187 */188188 halt: function(code, body) {189 halt: function(code, body, encoding) {190 this.status(code = code || 404)191 if (body = body || statusBodies[code])191 return this.respond(body)192 return this.respond(body, encoding)193 throw new InvalidStatusCode(code)194 },195 196 /**196 * Respond with _body_.197 * Respond with _body_ and optional _encoding_.198 *198 * @param {Type} Var199 * @return {Type}199 * @param {string} body200 * @param {string} encoding201 * @see Request#halt()202 * @api private203 */204 204 respond: function(body) {205 respond: function(body, encoding) {206 this.response.body = body207 this.trigger('response')208 if (typeof this.response.body != 'string') throw new InvalidResponseBody(this)209 if (typeof this.response.status != 'number') throw new InvalidStatusCode(this.response.status)210 this.response.sendHeader(this.response.status, this.response.headers)210 this.response.sendBody(this.response.body)211 this.response.sendBody(this.response.body, encoding)212 this.response.finish()213 },214 215 /**
41 unmodified lines
modified:lib/express/static.js+1 added-1 removed
modified:Readme.md+1 added-1 removed