Fixed status()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 2a7cdd4 · Browse files · 2 files·+50 added−23 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+50 added−23 removed
- tests:+41 added−0 removed
- other:+9 added−23 removed
Provenance
- Commit
61d0aa1- Tree
7c35c17- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
2a7cdd4
2 files changed+50 added−23 removed
modified:lib/express.core.js+9 added-23 removed
4 unmodified lines5 routes : [],6 response : {7 body : null,8 status : 200,9- headers : {},10- statuses : {11- 'ok' : 200,12- 'created' : 201,13- 'accepted' : 202,14- 'no content' : 204,15- 'reset content' : 205,16- 'partial content' : 206,17- 'moved permanently' : 301,18- 'found' : 302,19- 'see other' : 303,20- 'not modified' : 304,21- 'use proxy' : 305,22- 'switch proxy' : 306,23- 'temporary redirect' : 307,24- 'bad request' : 400,25- 'unauthorized' : 401,26- 'forbidden' : 403,27- 'not found' : 40428- }9+ headers : {}10 },11 12 defaultRoute : {13 callback : function() {46 unmodified lines60 */61 62 hashToArray : function(hash) {63 var array = []83- for (key in hash)64+ for (var key in hash)65 if (hash.hasOwnProperty(key))66 array.push([key, hash[key]])67 return array68 },19 unmodified lines88 * a case-insensitive string such as 'Not Found', 'forbidden',89 * or a numeric HTTP response status code.90 *91 * @param {int, string} value92+ * @return {int}93 * @api public94 */95 96 status : function(value) {115- this.response.status = this.response.statuses[value.toString().toLowerCase()] || value97+ if (typeof value == 'number') return this.response.status = value98+ for (var code in node.http.STATUS_CODES)99+ if (node.http.STATUS_CODES.hasOwnProperty(code))100+ if (node.http.STATUS_CODES[code].toLowerCase() == value.toLowerCase())101+ return this.response.status = code102 },103 104 /**105 * Sets _name_ header to _value_. When _value_24 unmodified lines130 return this.request.uri.params[key] || defaultValue131 },132 133 parseNestedParams : function(params) {148- for (key in params)134+ for (var key in params)135 if (params.hasOwnProperty(key))136 if (parts = key.split('['))137 if (parts.length > 1)138 for (i = 0, prop = params, len = parts.length; i < len; ++i) {203 unmodified linesmodified:spec/spec.core.js+41 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454694 unmodified lines
node = { http : {}}node.http.STATUS_CODES = { 100 : 'Continue', 101 : 'Switching Protocols', 200 : 'OK', 201 : 'Created', 202 : 'Accepted', 203 : 'Non-Authoritative Information', 204 : 'No Content', 205 : 'Reset Content', 206 : 'Partial Content', 300 : 'Multiple Choices', 301 : 'Moved Permanently', 302 : 'Moved Temporarily', 303 : 'See Other', 304 : 'Not Modified', 305 : 'Use Proxy', 400 : 'Bad Request', 401 : 'Unauthorized', 402 : 'Payment Required', 403 : 'Forbidden', 404 : 'Not Found', 405 : 'Method Not Allowed', 406 : 'Not Acceptable', 407 : 'Proxy Authentication Required', 408 : 'Request Time-out', 409 : 'Conflict', 410 : 'Gone', 411 : 'Length Required', 412 : 'Precondition Failed', 413 : 'Request Entity Too Large', 414 : 'Request-URI Too Large', 415 : 'Unsupported Media Type', 500 : 'Internal Server Error', 501 : 'Not Implemented', 502 : 'Bad Gateway', 503 : 'Service Unavailable', 504 : 'Gateway Time-out', 505 : 'HTTP Version not supported'}
describe 'Express' describe '.version' it 'should be properly formatted' Express.version.should.match /\d+\.\d+\.\d+/94 unmodified lines