Skip to main content
Version: 8.2405.x.x RR

WebSocketFrame object methods

A websocketframe is passed in the function defined in Script.InputWebSocketFrameFunctionName and Script.OutputWebSocketFrameFunctionName of the LuaFilter.

The first parameter of the function is a WebSocketFrame, the second the data which depends on the opCode of the WebSocketFrame. In this example the websocket stream gets closed if there is the word 'blockme' in a text frame:

function websocketIn(frame, data)
if frame:getOpCode() == 1 then
if string.find(data, "blockme") then
frame:block()
end
end
end

isFin()

Returns true if this is more frames of this message follow. Returns false if this is the final frame of this message.

function websocketIn(frame, data)
local isFin = frame:isFin()
end

getOpCode()

Returns the opcode as a number. The following opcodes are supported (see also https://www.rfc-editor.org/rfc/rfc6455#page-28):

  • 0 denotes a continuation frame
  • 1 denotes a text frame
  • 2 denotes a binary frame
  • 3-7 are reserved for further non-control frames
  • 8 denotes a connection close
  • 9 denotes a ping
  • 10 denotes a pong
  • 11-15 are reserved for further control frames

see above for an example.

block()

A call to this function will close the websocket connection. See above for an example.