NAME
Net::Inspect::L7::HTTP::WebSocket - implements WebSocket-upgrade
SYNOPSIS
package myRequest;
use base 'Net::Inspect::Flow';
# define methods needed by Net::Inspect::L7::HTTP
sub in_request_header { ... }
...
use base 'Net::Inspect::L7::HTTP::WebSocket';
# define the methods needed for WebSockets
sub in_wsctl { ... }
sub in_wsdata { ... }
DESCRIPTION
This module implements the upgrade_websocket method which gets called by Net::Inspect::L7::HTTP if an upgrade to websockets is encountered:
- $request->update_websocket($conn,$request,$response) -> $sub
-
If this function is implemented in the request object by deriving from this class it will check if the current upgrade is a valid websocket upgrade by inspecting
$requestand <$response>. These hashes are a the result ofparse_reqhdrandparse_rsphdrin Net::Inspect::L7::HTTP.The Net::Inspect::L7::HTTP object is also given, because it will be used (as a weak reference) in the callback
$subwhich gets returned if the connection upgrade was considered is valid.This callback
$subwill then be called as$sub->($dir,$data,$eof,$time)similar toin_dataas documented in Net:Inspect::L7::HTTP. Based on the input$subwill then forward toin_wsctlorin_wsdatawhich need to be defined by the request object.If the upgrade fails because the information sent in the headers are not correct the function will throw an error (i.e. die()) which will be catched by the caller
$connand will cause the connection to be declared bad.
The following functions will be called on new data and will need to be defined by the request object:
- $request->in_wsctl($dir,$data,$time,$frameinfo)
-
This will be called after a Websocket upgrade when receiving a control frame.
$diris 0 for data from client, 1 for data from server.$datais the unmasked payload of the frame.$frameinfois a blessed hash reference which contains theopcodeof the frame, themask(binary) andheaderfor the frame header. For a close frame it will also contain the extractedstatuscode and thereason.To get the unmasked payload call
$frameinfo->unmask($masked_data).in_wsctlwill be called on connection close with$dataof''and no\%frameinfo(i.e. no hash reference). - $request->in_wsdata($dir,$data,$eom,$time,$frameinfo)
-
This will be called after a Websocket upgrade when receiving data inside a data frame. Contrary to (the short) control frames the data frame must not be read fully before calling
in_wsdata.$diris 0 for data from client, 1 for data from server.$datais the unmasked payload of the frame.$eomis true if the message is done with this call, that is if the data frame is done and the FIN bit was set on the frame.$frameinfois a blessed hash reference which contains the data type asopcode. This will be the original opcode of the starting frame in case of fragmented transfer. It will also contain themask(binary) of the current frame.If this is the initial part of the data (i.e. initial frame in possibly fragmented data and initial data inside this frame) it will also have
initset to true inside$frameinfo.If there are still unread data within the frame
$frameinfowill containbytes_leftas<[hi,low]> wherehiandloware the upper and lower 32 bit parts of the number of outstanding bytes.If this call to
in_wsdatawas caused by the start of a new frame and not further data in the same frameheaderwill be set to the header of this new frame. In all other casesheaderis not set.To get the unmasked payload call
$frameinfo->unmask($masked_data).