Skip to content

Commit

Permalink
Added encoding param to Request#halt() and Request#respond()
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Dec 29, 2009
1 parent b1a2b7b commit dd5d4cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Expand Up @@ -94,7 +94,7 @@ Run individual suites:
...

Express is currently being developed with node --version:
v0.1.21-19-g3a21e60
v0.1.21-66-g59a78d6

## License

Expand Down
17 changes: 9 additions & 8 deletions lib/express/request.js
Expand Up @@ -171,7 +171,7 @@ exports.Request = Class({
},

/**
* Immediately respond with response _code_ and _body_.
* Immediately respond with response _code_, _body_ and optional _encoding_.
* The status _code_ defaults to to 404, and _body_ will
* default to the default body associated with the response
* _code_.
Expand All @@ -181,33 +181,34 @@ exports.Request = Class({
*
* @param {int} code
* @param {string} body
* @param {string} encoding
* @see statusBodies
* @api public
*/

halt: function(code, body) {
halt: function(code, body, encoding) {
this.status(code = code || 404)
if (body = body || statusBodies[code])
return this.respond(body)
return this.respond(body, encoding)
throw new InvalidStatusCode(code)
},

/**
* Respond with _body_.
* Respond with _body_ and optional _encoding_.
*
* @param {Type} Var
* @return {Type}
* @param {string} body
* @param {string} encoding
* @see Request#halt()
* @api private
*/

respond: function(body) {
respond: function(body, encoding) {
this.response.body = body
this.trigger('response')
if (typeof this.response.body != 'string') throw new InvalidResponseBody(this)
if (typeof this.response.status != 'number') throw new InvalidStatusCode(this.response.status)
this.response.sendHeader(this.response.status, this.response.headers)
this.response.sendBody(this.response.body)
this.response.sendBody(this.response.body, encoding)
this.response.finish()
},

Expand Down
2 changes: 1 addition & 1 deletion lib/express/static.js
Expand Up @@ -48,7 +48,7 @@ exports.File = Class({
if (!stats.isFile()) request.halt()
posix.cat(file, 'binary').addCallback(function(content){
request.contentType(file)
request.halt(200, content)
request.halt(200, content, 'binary')
})
})
})
Expand Down

0 comments on commit dd5d4cc

Please sign in to comment.