mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 00:19:48 +01:00
Added Express.status() and specs
This commit is contained in:
parent
3b3be54142
commit
aa01cc2bd8
|
|
@ -2,7 +2,29 @@
|
|||
(function(){
|
||||
Express = {
|
||||
version : '0.0.1',
|
||||
headers : {},
|
||||
response : {
|
||||
status : 200,
|
||||
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_.
|
||||
|
|
@ -35,6 +57,19 @@
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 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_
|
||||
|
|
@ -46,7 +81,8 @@
|
|||
*/
|
||||
|
||||
header : function(name, value) {
|
||||
return value ? this.headers[name] = value : this.headers[name]
|
||||
return value ? this.response.headers[name] = value :
|
||||
this.response.headers[name]
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,4 +18,25 @@ describe 'Express'
|
|||
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
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user