| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1037,6 +1037,21 @@ ensure the response is a properly formatted HTTP response message. | |||
| 1037 | 1037 | correctly; | |
| 1038 | 1038 | * `rawPacket`: the raw packet of current request. | |
| 1039 | 1039 | ||
| 1040 | + In some cases, the client has already received the response and/or the socket | ||
| 1041 | + has already been destroyed, like in case of `ECONNRESET` errors. Before | ||
| 1042 | + trying to send data to the socket, it is better to check that it is still | ||
| 1043 | + writable. | ||
| 1044 | + | ||
| 1045 | + ```js | ||
| 1046 | + server.on('clientError', (err, socket) => { | ||
| 1047 | + if (err.code === 'ECONNRESET' || !socket.writable) { | ||
| 1048 | + return; | ||
| 1049 | + } | ||
| 1050 | + | ||
| 1051 | + socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); | ||
| 1052 | + }); | ||
| 1053 | + ``` | ||
| 1054 | + | ||
| 1040 | 1055 | ### Event: `'close'` | |
| 1041 | 1056 | <!-- YAML | |
| 1042 | 1057 | added: v0.1.4 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments