Merge branch 'master' of git://github.com/visionmedia/express
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Conflicts: lib/express/static.js
authored by ciaranj · committed by ciaranj · parents 3ec970b, 3777bfd · Browse files · 4 files·+33 added−44 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+33 added−44 removed
- other:+33 added−44 removed
Provenance
- Commit
17ab8e8- Tree
b9618e9- Author
ciaranj <ciaranj@gmail.com>- Committer
ciaranj <ciaranj@gmail.com>- Parent 1
3ec970b- Parent 2
3777bfd
4 files changed+33 added−44 removed
modified:lib/express/core.js+2 added-2 removed
198 unmodified lines199 */200 201 run: function(host, port){202 var self = this203- if (host) this.host = host204- if (port) this.port = port203+ if (host !== undefined) this.host = host204+ if (port !== undefined) this.port = port205 require('http')206 .createServer(function(request, response){207 request.body = ''208 request.setBodyEncoding('utf8')62 unmodified linesmodified:lib/express/request.js+9 added-8 removed
169 unmodified lines170 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 line180 * will be thrown.181 *182 * @param {int} code183 * @param {string} body184+ * @param {string} encoding185 * @see statusBodies186 * @api public187 */188 188- 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 linesmodified:lib/express/static.js+15 added-32 removed
10 unmodified lines1112131415151617181920 unmodified lines40414243444546474748495051525152535455565758596061626364656667686970717273747576777879805354555657585960616263646510 unmodified lines init: function(path) { this.message = "`" + path + "' is not a valid path" }})
var static_file_cache={}; // --- File
20 unmodified lines * * @param {Request} request * @api public */ send: function(request) { var file = this.path if ( set('cache statics') && (content= static_file_cache[escape(file)]) ) { this._sendBinaryContent(request, file, content); request.contentType(file) request.halt(200, content, 'binary') } else { var fileInstance= this; path.exists(file, function(exists){ if (!exists) request.halt() posix.stat(file).addCallback(function(stats){ if (!stats.isFile()) request.halt() posix.cat(file, "binary").addCallback(function(content){ if( set('cache statics') ) { static_file_cache[escape(file)]= content; } fileInstance._sendBinaryContent(request, file, content); }) }) }) } }, /** * Private method to send binary content back as the * response body. * @param {Request} request * @param {string} file * @param {string} content * @api private */ _sendBinaryContent: function(request, file, content) { request.contentType(file) request.status(200) request.response.body = content request.trigger('response') request.response.sendHeader(request.response.status, request.response.headers) request.response.sendBody(request.response.body, 'binary') request.response.finish() path.exists(file, function(exists){ if (!exists) request.halt() posix.stat(file).addCallback(function(stats){ if (!stats.isFile()) request.halt() posix.cat(file, 'binary').addCallback(function(content){ request.contentType(file) request.halt(200, content, 'binary') }) }) }) } }})No newline at end of fileNo newline at end of filemodified:Readme.md+7 added-2 removed
92 unmodified lines939495969797989910010110210310410510610710310810911011111215 unmodified lines92 unmodified lines $ node spec/spec.node.js routing ...
Express is currently being developed with node --version: v0.1.21-19-g3a21e60 v0.1.21-66-g59a78d6 ## Contributors
* TJ Holowaychuk (visionmedia) <tj@vision-media.ca>* Ciaran Jessup (ciaranj) <ciaranj@gmail.com> ## License
(The MIT License)
Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the'Software'), to deal in the Software without restriction, including15 unmodified lines