Using the Sec-WebSocket-Protocol
Using the Sec-WebSocket-Protocol
Learn how to to use the Sec-WebSocket-Protocol with Deepgram APIs to send secure client side requests via web sockets.
Using the Sec-WebSocket-Protocol
Learn how to to use the Sec-WebSocket-Protocol with Deepgram APIs to send secure client side requests via web sockets.
The Sec-WebSocket-Protocol header plays a crucial role in WebSocket communications by enabling the client and server to agree on a specific subprotocol. Subprotocols define a higher-level protocol that runs over the WebSocket connection, specifying the format and semantics of the exchanged messages. This guide aims to provide a comprehensive understanding of how to use this header with Deepgram’s Listen WebSocket and and Speak WebSocket endpoint to facilitate seamless , secure and structured communication.
The use of this header is only required when making “client side” connections to Deepgram, where custom Authorization headers are prohibited by security measures in apps, including web apps, mobile apps and certain desktop apps.
When utilizing custom subprotocols in WebSocket communications, several security considerations must be addressed to ensure safe and reliable connections. Failure to do so can expose both the client and server to various risks, including unauthorized access, data breaches, and denial-of-service attacks.
Authentication and Authorization:
Data Encryption:
Input Validation and Sanitization:
Rate Limiting and Throttling:
Message Integrity:
Session Management:
Error Handling:
Protection Against Common Attacks:
Custom Subprotocol Security:
Compliance and Best Practices:
To use the Sec-WebSocket-Protocol header with Deepgram’s Listen WebSocket endpoint, follow this example:
In this example, the Sec-WebSocket-Protocol header specifies two subprotocols: token and a valid Deepgram API Key. During the WebSocket handshake, the server will select one of these subprotocols for the communication and authentication.
Replace YOUR_DEEPGRAM_API_KEY with your Deepgram API Key.
To use the Sec-WebSocket-Protocol header with Deepgram’s Speak WebSocket endpoint, follow this example:
In this example, the Sec-WebSocket-Protocol header specifies two subprotocols: token and a valid Deepgram API Key. During the WebSocket handshake, the server will select one of these subprotocols for the communication and authentication.
Replace YOUR_DEEPGRAM_API_KEY with your Deepgram API Key.