Customizing WebSocket client headers lets you inject specific information, preferences, or requirements into the WebSocket connection establishment process.
From 4D v20 R3, you can transmit security information, application-specific data, or other data relevant to the server connection through websocket client headers.
Here is everything you need to know!
As described in the Websocket client blog post, you must create a class to manage the websocket events.
This class supports a new attribute, headers, which is an object where the attributes have this syntax: headers.key:=value.
For example, if you want to transmit an authorization token to the server, you need to create a class we’ll call WSConnectionHandler class :
Class constructor($myToken:Text)
// Creation of the headers sent to the server
This.headers:=New object ("x-authorization";$myToken)
// Cookie header should use this syntax:
This.headers.Cookie:="yummy_cookie=choco; tasty_cookie=strawberry"
Function onMessage($ws : Object; $event : Object)
Form.messages.push($event.data)
Function onTerminate($ws : Object; $event : Object)
Form.messages.push("Connection closed")
Check out the documentation for more details! And feel free to join the discussion on the 4D Forums.