summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Insogna <paolo@cowtech.it>2020-05-08 12:27:52 +0200
committerMatteo Collina <hello@matteocollina.com>2020-05-12 20:02:49 +0200
commit5bb4d01fbe1242c89eda198b92c0899da3736dbd (patch)
treef63c2b055812624c3255ab30cbe93a249d0f063a
parent0ddae48b888838b27a1878e636444e968237e61b (diff)
downloadnode-new-5bb4d01fbe1242c89eda198b92c0899da3736dbd.tar.gz
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>
-rw-r--r--doc/api/http.md15
1 files changed, 15 insertions, 0 deletions
diff --git a/doc/api/http.md b/doc/api/http.md
index e924a2dc31..4d6c234245 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