diff options
author | Paolo Insogna <paolo@cowtech.it> | 2020-05-08 13:27:52 +0300 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2020-05-12 21:02:49 +0300 |
commit | 5bb4d01fbe1242c89eda198b92c0899da3736dbd (patch) | |
tree | f63c2b055812624c3255ab30cbe93a249d0f063a /doc/api/http.md | |
parent | 0ddae48b888838b27a1878e636444e968237e61b (diff) |
doc: add note about clientError writable handling
PR-URL: https://github.com/nodejs/node/pull/33308
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'doc/api/http.md')
-rw-r--r-- | doc/api/http.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/api/http.md b/doc/api/http.md index e924a2dc312..4d6c234245d 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -1045,6 +1045,21 @@ ensure the response is a properly formatted HTTP response message. correctly; * `rawPacket`: the raw packet of current request. +In some cases, the client has already received the response and/or the socket +has already been destroyed, like in case of `ECONNRESET` errors. Before +trying to send data to the socket, it is better to check that it is still +writable. + +```js +server.on('clientError', (err, socket) => { + if (err.code === 'ECONNRESET' || !socket.writable) { + return; + } + + socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); +}); +``` + ### Event: `'close'` <!-- YAML added: v0.1.4 |