Added Express.status() and specs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 3b3be54 · Browse files · 2 files·+59 added−2 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+59 added−2 removed
- tests:+21 added−0 removed
- other:+38 added−2 removed
Provenance
- Commit
aa01cc2- Tree
4806302- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
3b3be54
2 files changed+59 added−2 removed
modified:lib/express.core.js+38 added-2 removed
12345657891011121314151617181920212223242526272829303125 unmodified lines5758596061626364656667686970717273747576772 unmodified lines808182834984858687888913 unmodified lines
(function(){ Express = { version : '0.0.1', response : { status : 200, headers : {}, headers : {}, statuses : { 'ok' : 200, 'created' : 201, 'accepted' : 202, 'no content' : 204, 'reset content' : 205, 'partial content' : 206, 'moved permanently' : 301, 'found' : 302, 'see other' : 303, 'not modified' : 304, 'use proxy' : 305, 'switch proxy' : 306, 'temporary redirect' : 307, 'bad request' : 400, 'unauthorized' : 401, 'forbidden' : 403, 'not found' : 404 } }, /** * Start express, binding to _port_. *25 unmodified lines } }, /** * Set response status to _value_. Where value may be * a case-insensitive string such as 'Not Found', 'forbidden', * or a numeric HTTP response status code. * * @param {int, string} value * @api public */ status : function(value) { this.response.status = this.response.statuses[value.toString().toLowerCase()] || value }, /** * Sets _name_ header to _value_. When _value_ * is not present the value of the header _name_ * will be returned (if available). *2 unmodified lines * @api public */ header : function(name, value) { return value ? this.headers[name] = value : this.headers[name] return value ? this.response.headers[name] = value : this.response.headers[name] }, /** * Return the contents of a function body.13 unmodified linesmodified:spec/spec.core.js+21 added
16 unmodified lines171819202122232425262728293031323334353637383940414216 unmodified lines Express.header('Content-Type', 'text/html') Express.header('Content-Type').should.eql 'text/html' end end describe '.status()' after_each Express.response.status = 200 end it 'should set response status code by number' Express.status(404) Express.response.status.should.eql 404 end it 'should set using the status string map' Express.status('Not Found') Express.response.status.should.eql 404 end it 'should be case insensitive' Express.status('forbidden') Express.response.status.should.eql 403 end endendNo newline at end of fileNo newline at end of file