Skip to content
Myr

Added support for Request#halt(status, null) (empty response body)

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

authored by visionmedia · committed by visionmedia · parent 8a074a7 · Browse files · 4 files+18 added−14 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+18 added−14 removed

  • tests:+1 added−1 removed
  • other:+17 added−13 removed

4 files+18 added−14 removed

modified:lib/express/plugins/content-length.js+2 added-3 removed
modified:lib/express/plugins/static.js+2 added-3 removed
modified:lib/express/spec/mocks.js+1 added-1 removed
89 unmodified lines
90 /**91 * Store _code_ and _headers_.92 */93 94 writeHeader: function(code, headers) {94 writeHead: function(code, headers) {95 this.status = code96 this.headers = headers97 },98
80 unmodified lines
modified:lib/express/request.js+13 added-7 removed
172 unmodified lines
173 if (encoding instanceof Function)174 callback = encoding,175 encoding = null176 this.status(code = code || 404)177 if (body = body || statusBodies[code])178 return this.respond(body, encoding, callback)177 if (body !== null)178 body = body || statusBodies[code]179 return this.respond(body, encoding, callback)180 },181 182 /**183 * Respond with _body_ and optional _encoding_.
10 unmodified lines
194 this.trigger('response', function(err) {195 if (err)196 if (callback !== undefined) callback(err)197 else self.error(err)198 // TODO: revisit. when this is true node will add Transfer-Encoding: chunked199 // along with a response body, which is not ideal when the user attemps200 // to respond with no body201 if (!body) self.response.useChunkedEncodingByDefault = false197 self.response.writeHeader(self.response.status, self.response.headers)198 self.response.write(self.response.body, encoding)202 self.response.writeHead(self.response.status, self.response.headers)203 if (body) self.response.write(self.response.body, encoding)204 self.response.end()205 }, true)206 },207
17 unmodified lines
225 if (callback !== undefined) callback(err)226 })227 .addListener('data', function(data){228 if (first) {224 self.status(200)229 first = false230 self.header('Transfer-Encoding', 'chunked')231 self.status(200)232 self.contentType(stream.path)227 self.response.writeHeader(self.response.status, self.response.headers)233 self.response.writeHead(self.response.status, self.response.headers)234 }235 self.response.write(data, 'binary')236 })237 .addListener('end', function(){232 self.response.end()238 self.trigger('response', function(err){239 if (err) {240 stream.destroy()241 if (callback !== undefined) callback(err)242 else self.error(err)243 }244 self.response.end()245 }, true)246 })247 },248
147 unmodified lines