Sending custom headers in websocket handshake

python, websocket

Solution

In the python websocket-client you can indeed pass custom headers easily - there's a keyword argument `header` available for this; see the following example from the docs:

conn = create_connection("ws://echo.websocket.org/", header={"User-Agent": "MyProgram"})

Edit: Keyword should be `header`, not `headers`.

Problem

How to send custom headers in the first handshake that occurs in the WebSocket protocol? I want to use custom header in my initial request "**X-Abc-Def : xxxxx" WebSocket clients are Python & Android client.

Original source