mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
565 stars 127 forks source link

WebSocket: `wasClean` is incorrectly set to `true` on clean closures #610

Closed kettanaito closed 3 months ago

kettanaito commented 3 months ago

Per WHATWG WebSocket spec:

7.1.4. The WebSocket Connection is Closed

When the underlying TCP connection is closed, it is said that The WebSocket Connection is Closed and that the WebSocket connection is in the CLOSED state. If the TCP connection was closed after the WebSocket closing handshake was completed, the WebSocket connection is said to have been closed cleanly.

If the WebSocket connection could not be established, it is also said that The WebSocket Connection is Closed, but not cleanly. Source

This means that regardless of the closure code, wasClean will be true as long as the closing handshake has been performed before that.

I translate this as: only closure due to errors are not considered clean.

We should support a wasClean?: boolean parameter in the [kClose] method on WebSocketOverride so that we can set it to false only in the case when we close the connection with error (e.g. when an unhandled exception occurred in the interceptor).

kettanaito commented 3 months ago

Released: v0.34.1 🎉

This has been released in v0.34.1!

Make sure to always update to the latest version (npm i @mswjs/interceptors@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.