Skip to content
Myr

Moving more helpers to Request methods

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

authored by visionmedia · committed by visionmedia · parent a71a601 · Browse files · 2 files+88 added−90 removed
This commit

State

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

Diff stats

2 files+88 added−90 removed

  • other:+88 added−90 removed

2 files+88 added−90 removed

modified:lib/express/helpers.js-90 removed
modified:lib/express/request.js+88 added
12// Express - Request - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Default response code bodies.6 */78var statusBodies = {9 100: 'Continue',10 101: 'Switching Protocols',11 200: 'OK',12 201: 'Created',13 202: 'Accepted',14 203: 'Non-Authoritative Information',15 204: 'No Content',16 205: 'Reset Content',17 206: 'Partial Content',18 300: 'Multiple Choices',19 301: 'Moved Permanently',20 302: 'Moved Temporarily',21 303: 'See Other',22 304: 'Not Modified',23 305: 'Use Proxy',24 400: 'Bad Request',25 401: 'Unauthorized',26 402: 'Payment Required',27 403: 'Forbidden',28 404: 'Not Found',29 405: 'Method Not Allowed',30 406: 'Not Acceptable',31 407: 'Proxy Authentication Required',32 408: 'Request Time-out',33 409: 'Conflict',34 410: 'Gone',35 411: 'Length Required',36 412: 'Precondition Failed',37 413: 'Request Entity Too Large',38 414: 'Request-URI Too Large',39 415: 'Unsupported Media Type',40 500: 'Internal Server Error',41 501: 'Not Implemented',42 502: 'Bad Gateway',43 503: 'Service Unavailable',44 504: 'Gateway Time-out',45 505: 'HTTP Version not supported'46}4748// --- InvalidStatusCode4950InvalidStatusCode = ExpressError.extend({51 name: 'InvalidStatusCode',52 init: function(status) {53 this.message = status + ' is an invalid HTTP response code'54 }55})5657// --- Helpers5859/**60 * Normalize the given _path_.
100 unmodified lines
161 return this.response.status = code162 },163 164 /**165 * Immediately respond with response _code_ and _body_.166 * The status _code_ defaults to to 404, and _body_ will167 * default to the default body associated with the response168 * _code_.169 *170 * When an invalid status _code_ is passed, InvalidStatusCode171 * will be thrown.172 *173 * @param {int} code174 * @param {string} body175 * @see statusBodies176 * @api public177 */178179 halt: function(code, body) {180 this.status(code = code || 404)181 if (body = body || statusBodies[code])182 return Express.server.respond(body)183 throw new InvalidStatusCode(code)184 },185 186 /**187 * Set Content-Type header to the mime type188 * for the given _path_, which calls mime().189 *190 * @param {string} path191 * @see mime()192 * @api public193 */194195 contentType: function(path) {196 this.header('content-type', mime(path))197 },198 199 /**200 * Trigger even _name_ with optional _data_.201 *202 * @param {string} name203 * @param {hash} data
13 unmodified lines