Module: WebSocket
- Extended by:
- WebSocket
- Included in:
- WebSocket
- Defined in:
- lib/websocket/parser.rb,
lib/websocket_parser.rb,
lib/websocket/message.rb,
lib/websocket/version.rb,
lib/websocket/client_handshake.rb,
lib/websocket/server_handshake.rb
Defined Under Namespace
Classes: ClientHandshake, Message, Parser, ParserError, ServerHandshake
Constant Summary collapse
- PROTOCOL_VERSION =
RFC 6455
13
- GUID =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
- CRLF =
"\r\n"
- OPCODES =
{ 0 => :continuation, 1 => :text, 2 => :binary, 8 => :close, 9 => :ping, 10 => :pong }
- OPCODE_VALUES =
{ :continuation => 0, :text => 1, :binary => 2, :close => 8, :ping => 9, :pong => 10 }
- STATUS_CODES =
{ 1000 => :normal_closure, 1001 => :peer_going_away, 1002 => :protocol_error, 1003 => :data_error, 1007 => :data_not_consistent, 1008 => :policy_violation, 1009 => :message_too_big, 1010 => :extension_required, 1011 => :unexpected_condition }
- VERSION =
"0.1.5"
Instance Method Summary collapse
-
#frame_format(payload_length, masked = false) ⇒ Object
Determines how to unpack the frame depending on the payload length and wether the frame is masked.
- #mask(data, mask_key) ⇒ Object (also: #unmask)
Instance Method Details
#frame_format(payload_length, masked = false) ⇒ Object
Determines how to unpack the frame depending on the payload length and wether the frame is masked
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/websocket_parser.rb', line 52 def frame_format(payload_length, masked = false) format = 'CC' if payload_length > 65_535 format += 'Q>' elsif payload_length > 125 format += 'n' end if masked format += 'a4' end if payload_length > 0 format += "a#{payload_length}" end format end |
#mask(data, mask_key) ⇒ Object Also known as: unmask
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/websocket_parser.rb', line 72 def mask(data, mask_key) masked_data = ''.encode!("ASCII-8BIT") mask_bytes = mask_key.bytes.to_a data.bytes.each_with_index do |byte, i| masked_data << (byte ^ mask_bytes[i%4]) end masked_data end |