Class: Protocol::WebSocket::Extensions::Client
- Inherits:
-
Object
- Object
- Protocol::WebSocket::Extensions::Client
- Defined in:
- lib/protocol/websocket/extensions.rb
Instance Attribute Summary collapse
-
#accepted ⇒ Object
readonly
Returns the value of attribute accepted.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
Class Method Summary collapse
Instance Method Summary collapse
- #accept(headers) ⇒ Object
- #apply(connection) ⇒ Object
-
#initialize(extensions = []) ⇒ Client
constructor
A new instance of Client.
- #named ⇒ Object
- #offer ⇒ Object
Constructor Details
#initialize(extensions = []) ⇒ Client
Returns a new instance of Client.
33 34 35 36 |
# File 'lib/protocol/websocket/extensions.rb', line 33 def initialize(extensions = []) @extensions = extensions @accepted = [] end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
39 40 41 |
# File 'lib/protocol/websocket/extensions.rb', line 39 def accepted @accepted end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
38 39 40 |
# File 'lib/protocol/websocket/extensions.rb', line 38 def extensions @extensions end |
Class Method Details
.default ⇒ Object
27 28 29 30 31 |
# File 'lib/protocol/websocket/extensions.rb', line 27 def self.default self.new([ [Extension::Compression, {}] ]) end |
Instance Method Details
#accept(headers) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/protocol/websocket/extensions.rb', line 55 def accept(headers) named = self.named # Each response header should map to at least one extension. Extensions.parse(headers) do |name, arguments| if extension = named.delete(name) klass, = extension = klass.accept(arguments, **) @accepted << [klass, ] end end end |
#apply(connection) ⇒ Object
70 71 72 73 74 |
# File 'lib/protocol/websocket/extensions.rb', line 70 def apply(connection) @accepted.each do |(klass, )| klass.client(connection, **) end end |
#named ⇒ Object
41 42 43 44 45 |
# File 'lib/protocol/websocket/extensions.rb', line 41 def named @extensions.map do |extension| [extension.first::NAME, extension] end.to_h end |
#offer ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/protocol/websocket/extensions.rb', line 47 def offer @extensions.each do |extension, | if header = extension.offer(**) yield header end end end |