Skip to content

Commit

Permalink
doc: add note about clientError writable handling
Browse files Browse the repository at this point in the history
PR-URL: #33308
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
ShogunPanda authored and mcollina committed May 12, 2020
1 parent 0ddae48 commit 5bb4d01
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5bb4d01

Please sign in to comment.