From db0875208d6770c667f42ca331c4b72a8f1a892e Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Fri, 13 Jun 2014 09:02:06 -0700 Subject: [PATCH] docs --- docs/api/response.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/api/response.md b/docs/api/response.md index 4e80207..fa79126 100644 --- a/docs/api/response.md +++ b/docs/api/response.md @@ -187,25 +187,24 @@ this.type = 'png'; Very similar to `this.request.is()`. Check whether the response type is one of the supplied types. This is particularly useful for creating middleware that - change certain responses. + manipulate responses. For example, this is a middleware that minifies - all HTML response except for streamss. + all HTML responses except for streams. ```js var minify = require('html-minifier'); app.use(function *minifyHTML(next){ - yield* next; + yield next; if (!this.response.is('html')) return; - var body = this.response.body; - if (!body) return; - // too difficult to do this with a stream - if ('function' == typeof body.pipe) return; - if (Buffer.isBuffer(body)) body = body.toString('utf8'); - this.response.body = minify(body); + var body = this.body; + if (!body || body.pipe) return; + + if (Buffer.isBuffer(body)) body = body.toString(); + this.body = minify(body); }); ```