Merge pull request #244 from t3chnoboy/master

ocd
This commit is contained in:
Jonathan Ong 2014-03-24 11:23:54 -07:00
commit d8b6a18c9d
7 changed files with 20 additions and 20 deletions

View file

@ -13,7 +13,7 @@
`X-Response-Time` header field the middleware would look like the following:
```js
function *responseTime(next){
function *responseTime(next) {
var start = new Date;
yield next;
var ms = new Date - start;
@ -88,7 +88,7 @@ app.use(function *response(){
and returns the middleware itself:
```js
function logger(format){
function logger(format) {
format = format || ':method ":url"';
return function *(next){
@ -111,7 +111,7 @@ app.use(logger(':method :url'));
Naming middleware is optional, however it's useful for debugging purposes to assign a name.
```js
function logger(format){
function logger(format) {
return function *logger(next){
}
@ -123,7 +123,7 @@ function logger(format){
Sometimes you want to "compose" multiple middleware into a single middleware for easy re-use or exporting. To do so, you may chain them together with `.call(this, next)`s, then return another function that yields the chain.
```js
function *random(next){
function *random(next) {
if ('/random' == this.path) {
this.body = Math.floor(Math.random()*10);
} else {
@ -139,7 +139,7 @@ function *backwords(next) {
}
}
function *pi(next){
function *pi(next) {
if ('/pi' == this.path) {
this.body = String(Math.PI);
} else {

View file

@ -162,7 +162,7 @@ app.onerror = function(err){
* Response middleware.
*/
function *respond(next){
function *respond(next) {
if (this.app.poweredBy) this.set('X-Powered-By', 'koa');
yield *next;
@ -217,4 +217,4 @@ function *respond(next){
this.length = Buffer.byteLength(body);
if (head) return res.end();
res.end(body);
}
}

View file

@ -486,7 +486,7 @@ module.exports = {
* @api public
*/
acceptsLanguages: function() {
acceptsLanguages: function(){
return this.accept.languages.apply(this.accept, arguments);
},

View file

@ -257,7 +257,7 @@ module.exports = {
* @api public
*/
set type(type){
set type(type) {
if (!~type.indexOf('/')) {
type = mime.lookup(type);
var cs = mime.charsets.lookup(type);

View file

@ -33,7 +33,7 @@ describe('app', function(){
this.status = 204;
// throw if .writeHead or .end is called
this.res.writeHead =
this.res.end = function () {
this.res.end = function(){
throw new Error('response sent');
};
})
@ -125,7 +125,7 @@ describe('app.respond', function(){
this.respond = false;
var res = this.res;
setImmediate(function () {
setImmediate(function(){
res.setHeader('Content-Type', 'text/plain');
res.end('lol');
})
@ -229,14 +229,14 @@ describe('app.respond', function(){
res.setHeader("Content-Type", "text/html")
res.status = 200;
res.write('Hello');
setTimeout(function () {
setTimeout(function(){
res.end("Goodbye")
}, 0);
});
var errorCaught = false;
app.on('error', function (err) {
app.on('error', function(err){
errorCaught = err;
});
@ -260,7 +260,7 @@ describe('app.respond', function(){
res.setHeader("Content-Type", "text/html")
res.status = 200;
res.write('Hello');
setTimeout(function () {
setTimeout(function(){
res.end("Goodbye")
}, 0);
});
@ -306,7 +306,7 @@ describe('app.respond', function(){
.get('/')
.expect(204)
.expect('')
.end(function (err, res) {
.end(function(err, res){
if (err) return done(err);
res.header.should.not.have.property('content-type');
@ -329,7 +329,7 @@ describe('app.respond', function(){
.get('/')
.expect(205)
.expect('')
.end(function (err, res) {
.end(function(err, res){
if (err) return done(err);
res.header.should.not.have.property('content-type');
@ -352,7 +352,7 @@ describe('app.respond', function(){
.get('/')
.expect(304)
.expect('')
.end(function (err, res) {
.end(function(err, res){
if (err) return done(err);
res.header.should.not.have.property('content-type');
@ -629,4 +629,4 @@ describe('app.response', function(){
.get('/')
.expect(204, done);
})
})
})

View file

@ -99,4 +99,4 @@ function escape(html) {
.replace(/"/g, '"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
}

View file

@ -65,4 +65,4 @@ describe('res.status=', function(){
describe('when 304', function(){
strip(304);
})
})
})