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
Provenance
- Commit
26b3a42- Tree
845a777- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
8a074a7
4 files changed+18 added−14 removed
modified:lib/express/plugins/content-length.js+2 added-3 removed
9 unmodified lines1011121314151614151617189 unmodified lines response: function(event) { var response = event.request.response if (!response.chunkedEncoding) response.headers['content-length'] = response.headers['content-length'] || response.body.length if (!response.headers['content-length'] && response.body) response.headers['content-length'] = response.body.length } }})No newline at end of fileNo newline at end of filemodified:lib/express/plugins/static.js+2 added-3 removed
55 unmodified lines5657585960606162633 unmodified lines67686970727371727374757621 unmodified lines55 unmodified lines callback = options, options = {} if (path.indexOf('..') !== -1) Error.raise('InvalidPathError', "`" + path + "' is not a valid path") this.response.chunkedEncoding = true fs.stat(path, function(err, stat){ if (err) if (callback !== undefined) return callback(err)3 unmodified lines : self.error(err) var etag = stat.ino + '-' + stat.size + '-' + Number(stat.mtime) if (self.header('if-none-match') && self.header('if-none-match') == etag) return self.halt(304) // TODO: fails to render... self.header('content-length', stat.size) return self.halt(304, null) self.header('content-length', stat.size) self.header('etag', etag) self.stream(fs.createReadStream(path, options)) }) return this21 unmodified linesmodified:lib/express/spec/mocks.js+1 added-1 removed
89 unmodified lines90 /**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 linesmodified:lib/express/request.js+13 added-7 removed
172 unmodified lines173 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 lines194 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 lines225 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