Use a guard flag to prevent done() from being called multiple times.
This handles the case where:
- If connected: destroy() triggers close event -> callDone()
- If not connected: callDone() is called directly as safety net
- Guard prevents double-call if close event fires after direct call
Addresses review feedback from @knolleary.
Fixes#5452
This PR fixes several issues that can cause uncaught exceptions and crash Node-RED:
1. Fixed typo: `toLowercase()` -> `toLowerCase()` in getHeaderValue()
2. Added try-catch to beforeRequest hook
3. Added try-catch to beforeRedirect hook
4. Added try-catch to afterResponse hook (digest auth)
5. Added input validation to extractCookies() with array check
6. Added input validation to buildDigestHeader() for nonce/realm
These changes ensure that malformed responses or invalid data from servers
don't crash the entire Node-RED runtime.
Fixes: Uncaught exceptions in HTTP request node
fixes#5251
The code changed from 4.0.x to 4.1.x
This change to to prevent making changes to the orginial input `msg`
object incase any values were stored in context (pass by refernce).
The change meant that for every output message the whole original
input `msg` was being cloned, which could be huge, causing a big
performance regresion.
This fix ensures the clone of the orginial `msg` is only done once
and the much smaller output message is then cloned again to update
`msg.parts` object for each output. This results in lots of small
clones rather than lots of very large clones.
The inject node was using a restrictive regex that only accepted decimal
numbers, while the switch node properly supported binary (0b) and
hexadecimal (0x) formats. This inconsistency caused the inject node to
show validation errors for valid number formats.
Updated the inject node to use the same validateTypedProperty utility
function as the switch node, ensuring consistent number validation
across both nodes.
Fixes#5208