WebSocket

WebSocket 1007 Invalid Payload Data vs 1010 Mandatory Extension

Both WebSocket 1007 (Invalid Payload Data) and 1010 (Mandatory Extension) belong to the WebSocket Close Codes category. 1007 indicates that an endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data. Meanwhile, 1010 means that the client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.

Descripción

An endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data.

Cuándo lo verás

A text frame was received but its payload is not valid UTF-8. This commonly happens when binary data is accidentally sent as a text frame.

Cómo solucionarlo

Ensure text frames contain only valid UTF-8 encoded data. If you need to send raw bytes, use binary frames instead of text frames.

Descripción

The client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.

Cuándo lo verás

The client requested a required WebSocket extension (e.g., permessage-deflate compression) during the handshake, but the server did not include it in its response.

Cómo solucionarlo

Enable the required extension on the server, or update the client to make the extension optional. Check the Sec-WebSocket-Extensions header in the handshake response.

Diferencias clave

1.

WebSocket 1007: An endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data.

2.

WebSocket 1010: The client is terminating the connection because the server did not negotiate one or more expected extensions in the handshake response.

3.

You encounter 1007 when a text frame was received but its payload is not valid UTF-8. This commonly happens when binary data is accidentally sent as a text frame.

4.

You encounter 1010 when the client requested a required WebSocket extension (e.g., permessage-deflate compression) during the handshake, but the server did not include it in its response.

Cuándo usar cada uno

For 1007 (Invalid Payload Data): Ensure text frames contain only valid UTF-8 encoded data. If you need to send raw bytes, use binary frames instead of text frames. For 1010 (Mandatory Extension): Enable the required extension on the server, or update the client to make the extension optional. Check the Sec-WebSocket-Extensions header in the handshake response.

Saber más