More request specific refactoring
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent a499d15 · Browse files · 5 files·+28 added−26 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+28 added−26 removed
- other:+28 added−26 removed
Provenance
- Commit
0854753- Tree
8ea2825- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
a499d15
5 files changed+28 added−26 removed
modified:lib/express/pages/not-found.js+3 added-4 removed
123456789678910111217 unmodified lines
// Express - Pages - Not Found - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
var style = require('express/pages/style').style
exports.render = function() { contentType('html') var request = Express.server.request, method = request.method.toLowerCase(),exports.render = function(request) { request.contentType('html') var method = request.method.toLowerCase(), path = request.uri.path || '/' return '<html> \n\ <head> \n\ <title>Express -- Not Found</title> \n\17 unmodified linesmodified:lib/express/pages/show-exceptions.js+2 added-2 removed
12345676789101121 unmodified lines
// Express - Pages - Show Exceptions - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
var style = require('express/pages/style').style
exports.render = function(e) { contentType('html')exports.render = function(request, e) { request.contentType('html') if (e.stack) var stack = $(e.stack.split('\n').slice(1)).map(function(val, i){ if (!i) return '<li>' + val.replace(/^(.*?):/, '<span class="path">$1</span>:') + '</li>'21 unmodified linesmodified:lib/express/plugins/common-logger.js+1 added-1 removed
30 unmodified lines313233343535363738396 unmodified lines30 unmodified lines exports.CommonLogger = Plugin.extend({ on: { response: function(event) { puts([headers.host, puts([event.request.headers.host, '-', '-', '[' + format(new Date) + ']', '"' + event.request.method.toUpperCase() + ' ' + (event.request.uri.path || '/') + 6 unmodified linesmodified:lib/express/core.js+2 added-18 removed
119 unmodified lines120 var route = this.matchingRoute()121 if (route)122 return route.run(this.request.captures.slice(1))123 else if (this.request.accepts('html') && set('helpful 404'))124- this.request.halt(404, require('express/pages/not-found').render())124+ this.request.halt(404, require('express/pages/not-found').render(this.request))125 else126 this.request.halt()127 },128 105 unmodified lines234 catch (e) {235 if (e instanceof ExpressError)236 throw e237 if (request.accepts('html') && set('show exceptions'))238- request.halt(500, require('express/pages/show-exceptions').render(e))238+ request.halt(500, require('express/pages/show-exceptions').render(request, e))239 else240 request.halt(500)241 if (set('throw exceptions'))242 throw e243 }244- },245- 246- /**247- * Respond immediately with optional _body_.248- *249- * @param {string} body250- * @api private251- */252- 253- respond: function(body){254- this.response.body = body, trigger('response')255- if (typeof this.response.body != 'string') throw new InvalidResponseBody(this.request)256- if (typeof this.response.status != 'number') throw new InvalidStatusCode(this.response.status)257- this.response.sendHeader(this.response.status, this.response.headers)258- this.response.sendBody(this.response.body)259- this.response.finish()244 }245 })246 247 // --- Express15 unmodified linesmodified:lib/express/request.js+20 added-1 removed
177 unmodified lines178 179 halt: function(code, body) {180 this.status(code = code || 404)181 if (body = body || statusBodies[code])182- return Express.server.respond(body)182+ return this.respond(body)183 throw new InvalidStatusCode(code)184 },185 186 /**187+ * Respond with _body_.188+ *189+ * @param {Type} Var190+ * @return {Type}191+ * @see Request#halt()192+ * @api private193+ */194+ 195+ respond: function(body) {196+ this.response.body = body197+ this.trigger('response')198+ if (typeof this.response.body != 'string') throw new InvalidResponseBody(this)199+ if (typeof this.response.status != 'number') throw new InvalidStatusCode(this.response.status)200+ this.response.sendHeader(this.response.status, this.response.headers)201+ this.response.sendBody(this.response.body)202+ this.response.finish()203+ },204+ 205+ /**206 * Set Content-Type header to the mime type207 * for the given _path_, which calls mime().208 *209 * @param {string} path26 unmodified lines