This commit is contained in:
TJ Holowaychuk 2013-09-02 19:17:49 -07:00
parent 33221d6574
commit b132484dcf

View file

@ -39,19 +39,19 @@ app.use(function(next){
![koa middleware](https://i.cloudup.com/N7L5UakJo0.gif) ![koa middleware](https://i.cloudup.com/N7L5UakJo0.gif)
1. Create a date to track duration 1. Create a date to track duration
2. Yield control to the next middleware 2. Yield control to the next middleware
3. Create another date to track response time 3. Create another date to track response time
4. Yield control to the next middleware 4. Yield control to the next middleware
5. Yield immediately since `contentLength` only works with responses 5. Yield immediately since `contentLength` only works with responses
6. Yield upstream to Koa's noop middleware 6. Yield upstream to Koa's noop middleware
7. Ignore setting the body unless the path is "/" 7. Ignore setting the body unless the path is "/"
8. Set the response to "Hello World" 8. Set the response to "Hello World"
9. Ignore setting Content-Length when no body is present 9. Ignore setting Content-Length when no body is present
10. Set the field 10. Set the field
11. Output log line 11. Output log line
12. Set `X-Response-Time` header field before response 12. Set `X-Response-Time` header field before response
13. Hand off to Koa to handle the response 13. Hand off to Koa to handle the response
Note that the final middleware (step __6__) yields to what looks to be nothing - it's actually Note that the final middleware (step __6__) yields to what looks to be nothing - it's actually
yielding to a no-op generator within Koa. This is so that every middleware can conform with the yielding to a no-op generator within Koa. This is so that every middleware can conform with the