Question
· Dec 3, 2019

Retrieving headers from websocket upgrades

Hello,

I have a couple of IOT devices that communicate via WebSockets to our backend.

I successfully managed to create a websocket connection between server and (iot)client using %CSP.WebSocket
However I would like to implement authentication on this using the HTTP headers at the same time of Connection: Upgrade.

I tried to set the headers to globals in order to debug but they are always empty.

Example code: 

Method OnPreServer() As %Status
{
Try {
    s ^Header("HTTP_AUTHORIZATION")=%request.GetCgiEnv("HTTP_AUTHORIZATION")
    s ^Header("AUTHORIZATION")=%request.GetCgiEnv("AUTHORIZATION")
    s ^Header("REMOTE_USE")=%request.GetCgiEnv("REMOTE_USER")
    s ^Header("Sec-WebSocket-Protocol")=%request.GetCgiEnv("Sec-WebSocket-Protocol")
  } Catch {
    g ^%ETN
  }
  q $$$OK
}

Is there an other way to access the http headers before completing the websocket connection?

Discussion (1)0
Log in or sign up to continue