Skip to content

Commit

Permalink
docs: note stream error handling and destruction. ref: #612
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanong committed Mar 12, 2016
1 parent 86a6f2b commit d768ed8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/api/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ If `response.status` has not been set, Koa will automatically set the status to

The Content-Type is defaulted to application/octet-stream.

Whenever a stream is set as the response body, `.onerror` is automatically added as a listener to the `error` event to catch any errors.
In addition, whenever the request is closed (even prematurely), the stream is destroyed.
If you do not want these two features, do not set the stream as the body directly.
For example, you may not want this when setting the body as an HTTP stream in a proxy as it would destroy the underlying connection.

See: https://github.com/koajs/koa/pull/612 for more information.

Here's an example of stream error handling without automatically destroying the stream:

```js
const PassThrough = require('stream').PassThrough

app.use(function * (next) {
this.body = someHTTPStream.on('error', this.onerror).pipe(PassThrough())
})
```

#### Object

The Content-Type is defaulted to application/json.
Expand Down

0 comments on commit d768ed8

Please sign in to comment.