Reputation: 379
I know there are no standard JS WebSocket APIs for the same. My main aim is to send the info like resourceId
, routingInfo
, auth-token
, protocol
etc. from JS web-socketclient to the server.
I could think of below few approaches. Kindly share the thoughts if my approach is fine or is there any other better approach:
Can we use cookies for sending the custom headers from client and retrieve them in server side?
Can we use web-storage API for storing them in the browser and retrieve them on server side?
PS: I am using a Java based server
Upvotes: 4
Views: 6187
Reputation: 707318
Assuming you're talking about a webSocket connection from a browser, here are your traditional choices for sending additional "header-like" information.
auth-token
.As it sounds like you may already know, the browser interface to webSockets does not allow custom headers on the initial HTTP request that starts the webSocket connection. Those custom headers are possible from some other kind of client - it's just that the browser interface to a webSocket connection does not have that feature.
Can we use web-storage API for storing them in the browser and retrieve them?
The Javascript in your web page can use the web-storage API to store data in the browser and that data can be retrieved later from another script in a page from the same origin. That data is not available to the server, it is only available within the client.
Upvotes: 5