WebSocket compression update with new classes to
parse the compression header.
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
note
|
||||
description: "{COMPRESSION_EXTENSIONS_PARSER} Parse the SEC_WEBSOCKET_EXTENSION header as par of websocket opening handshake."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
EIS: "name=Compression Extension for WebSocket"
|
||||
|
||||
class
|
||||
COMPRESSION_EXTENSIONS_PARSER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialize
|
||||
|
||||
make (a_header: STRING_32)
|
||||
do
|
||||
header := a_header
|
||||
create {ARRAYED_LIST [WEBSOCKET_PCME]} last_offers.make (0)
|
||||
ensure
|
||||
header_set: header = a_header
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
header: STRING_32
|
||||
-- Content raw header `Sec-Websocket-Extensions'.
|
||||
|
||||
last_offers: LIST [WEBSOCKET_PCME]
|
||||
-- List of potential offered PMCE
|
||||
--| From Sec-Websocket-Extensions header.
|
||||
--| The order of elements is important as it specifies the client's preferences.
|
||||
|
||||
feature -- Parse
|
||||
|
||||
parse
|
||||
-- Parse `SEC-WEBSOCKET-EXTENSIONS' header.
|
||||
-- The result is available in `last_offer'.
|
||||
local
|
||||
l_offers: ARRAYED_LIST [WEBSOCKET_PCME]
|
||||
l_pcme: WEBSOCKET_PCME
|
||||
do
|
||||
create l_offers.make (1)
|
||||
if attached header.split (',') as l_list then
|
||||
-- Multiple offers separated by ',', if l_list.count > 1
|
||||
across l_list as ic loop
|
||||
-- Shared code extract to an external feature.
|
||||
l_offers.force (parse_parameters (ic.item))
|
||||
end
|
||||
else
|
||||
-- we should raise an Issue.
|
||||
end
|
||||
last_offers := l_offers
|
||||
end
|
||||
|
||||
feature {NONE}-- Parse Compression Extension.
|
||||
|
||||
parse_parameters (a_string: STRING_32): WEBSOCKET_PCME
|
||||
local
|
||||
l_first: BOOLEAN
|
||||
l_str: STRING_32
|
||||
l_key: STRING_32
|
||||
l_value: STRING_32
|
||||
do
|
||||
if attached a_string.split (';') as l_parameters then
|
||||
-- parameters for the current offer.
|
||||
create Result
|
||||
across
|
||||
l_parameters as ip
|
||||
from
|
||||
l_first := True
|
||||
loop
|
||||
if l_first then
|
||||
l_str := ip.item
|
||||
l_str.adjust
|
||||
Result.set_name (l_str)
|
||||
l_first := False
|
||||
else
|
||||
l_str := ip.item
|
||||
l_str.adjust
|
||||
if l_str.has ('=') then
|
||||
-- The parameter has a value
|
||||
-- server_max_window_bits = 10
|
||||
l_key := l_str.substring (1, l_str.index_of ('=', 1) - 1) -- Exclude =
|
||||
l_value := l_str.substring (l_str.index_of ('=', 1) + 1, l_str.count) -- Exclude =
|
||||
Result.force (l_value, l_key)
|
||||
else
|
||||
Result.force (Void, l_str)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Compression Extension simple
|
||||
--| like
|
||||
--| permessage-deflate
|
||||
l_str := a_string
|
||||
l_str.adjust
|
||||
create Result
|
||||
Result.set_name (l_str)
|
||||
end
|
||||
end
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,65 @@
|
||||
note
|
||||
description: "[Object that validate a PMCE permessage defalate extension,
|
||||
using the DEFLATE algorithm
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WEB_SOCKET_PMCE_DEFLATE_VALIDATOR
|
||||
|
||||
|
||||
feature -- Validate
|
||||
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: STRING = "permessage-deflate"
|
||||
-- registered extension name.
|
||||
|
||||
|
||||
parameters: STRING_TABLE [BOOLEAN]
|
||||
-- extension parameters
|
||||
note
|
||||
EIS: "name=Extension Parameters", "src=https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-28#section-7.1", "protocol=url"
|
||||
once
|
||||
create Result.make_caseless (4)
|
||||
Result.force (False, "server_no_context_takeover")
|
||||
Result.force (False, "client_no_context_takeover")
|
||||
Result.force (True, "server_max_windows_bits")
|
||||
Result.force (True, "client_max_windows_bits")
|
||||
end
|
||||
|
||||
|
||||
sliding_windows_size: STRING_TABLE [INTEGER]
|
||||
-- LZ77 sliding window size.
|
||||
--! Map with valid windows and the
|
||||
--! context parameter, and integer value
|
||||
--! between 8 and 15.
|
||||
note
|
||||
EIS:"name=Limiting the LZ77 sliding window size", "src=https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-28#section-7.1.2", "protocol=url"
|
||||
once
|
||||
create Result.make (7)
|
||||
Result.force (256, "8")
|
||||
Result.force (512, "9")
|
||||
Result.force (1024, "10")
|
||||
Result.force (2048, "11")
|
||||
Result.force (4096, "12")
|
||||
Result.force (8192, "13")
|
||||
Result.force (16384, "14")
|
||||
Result.force (32768, "15")
|
||||
end
|
||||
|
||||
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -0,0 +1,52 @@
|
||||
note
|
||||
description: "{WEBSOCKET_PCME}, object that represent a websocket per-message compression extension."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WEBSOCKET_PCME
|
||||
|
||||
feature -- Access
|
||||
|
||||
name: detachable STRING_32
|
||||
-- Compression extension name.
|
||||
|
||||
parameters: detachable STRING_TABLE [detachable STRING_32]
|
||||
-- Compression extensions parameter.
|
||||
|
||||
feature -- Change Element
|
||||
|
||||
set_name (a_name: STRING_32)
|
||||
-- Set name with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
force (a_value: detachable STRING_32; a_key: STRING_32)
|
||||
-- Update table `parameters' so that `a_value' will be the item associated
|
||||
-- with `a_key'.
|
||||
local
|
||||
l_parameters: like parameters
|
||||
do
|
||||
l_parameters := parameters
|
||||
if attached l_parameters then
|
||||
l_parameters.force (a_value, a_key)
|
||||
else
|
||||
create l_parameters.make_caseless (1)
|
||||
l_parameters.force (a_value, a_key)
|
||||
end
|
||||
parameters := l_parameters
|
||||
end
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
@@ -93,6 +93,9 @@ feature -- Access
|
||||
is_fin: BOOLEAN
|
||||
-- is the final fragment in a message?
|
||||
|
||||
is_rsv1: BOOLEAN
|
||||
-- is extension negotiation in a message?
|
||||
|
||||
fragment_count: INTEGER
|
||||
|
||||
payload_length: NATURAL_64
|
||||
@@ -132,6 +135,11 @@ feature -- Operation
|
||||
is_fin := a_flag_is_fin
|
||||
end
|
||||
|
||||
update_rsv1 (a_flag_rsv1: BOOLEAN)
|
||||
do
|
||||
is_rsv1 := a_flag_rsv1
|
||||
end
|
||||
|
||||
feature {WEB_SOCKET_FRAME} -- Change: injected control frames
|
||||
|
||||
add_injected_control_frame (f: WEB_SOCKET_FRAME)
|
||||
@@ -434,4 +442,14 @@ feature {NONE} -- Helper
|
||||
end
|
||||
end
|
||||
end
|
||||
note
|
||||
copyright: "2011-2016, Jocelyn Fiat, Javier Velilla, Eiffel Software and others"
|
||||
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
|
||||
source: "[
|
||||
Eiffel Software
|
||||
5949 Hollister Ave., Goleta, CA 93117 USA
|
||||
Telephone 805-685-1006, Fax 805-685-6869
|
||||
Website http://www.eiffel.com
|
||||
Customer support http://support.eiffel.com
|
||||
]"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user