Class: Protocol::WebSocket::Extensions::Client
- Inherits:
-
Object
- Object
- Protocol::WebSocket::Extensions::Client
- Defined in:
- lib/protocol/websocket/extensions.rb
Overview
Manages extensions on the client side, offering and accepting server responses.
Instance Attribute Summary collapse
-
#accepted ⇒ Object
readonly
Returns the value of attribute accepted.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
- #The extensions accepted after negotiation.(extensionsacceptedafternegotiation.) ⇒ Object readonly
- #The list of extensions to offer.(listofextensionstooffer.) ⇒ Object readonly
Class Method Summary collapse
-
.default ⇒ Object
Create a default client with permessage-deflate compression enabled.
Instance Method Summary collapse
-
#accept(headers) ⇒ Object
Accept server extension responses and record the negotiated extensions.
-
#apply(connection) ⇒ Object
Apply all accepted extensions to the given connection as a client.
-
#initialize(extensions = []) ⇒ Client
constructor
Initialize a new client extension manager.
-
#named ⇒ Object
Build a lookup table of extensions keyed by their name.
-
#offer ⇒ Object
Yield extension offer headers for each registered extension.
Constructor Details
#initialize(extensions = []) ⇒ Client
Initialize a new client extension manager.
44 45 46 47 |
# File 'lib/protocol/websocket/extensions.rb', line 44 def initialize(extensions = []) @extensions = extensions @accepted = [] end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
52 53 54 |
# File 'lib/protocol/websocket/extensions.rb', line 52 def accepted @accepted end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
50 51 52 |
# File 'lib/protocol/websocket/extensions.rb', line 50 def extensions @extensions end |
#The extensions accepted after negotiation.(extensionsacceptedafternegotiation.) ⇒ Object (readonly)
52 |
# File 'lib/protocol/websocket/extensions.rb', line 52 attr :accepted |
#The list of extensions to offer.(listofextensionstooffer.) ⇒ Object (readonly)
50 |
# File 'lib/protocol/websocket/extensions.rb', line 50 attr :extensions |
Class Method Details
.default ⇒ Object
Create a default client with permessage-deflate compression enabled.
36 37 38 39 40 |
# File 'lib/protocol/websocket/extensions.rb', line 36 def self.default self.new([ [Extension::Compression, {}] ]) end |
Instance Method Details
#accept(headers) ⇒ Object
Accept server extension responses and record the negotiated extensions.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/protocol/websocket/extensions.rb', line 76 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 return @accepted end |
#apply(connection) ⇒ Object
Apply all accepted extensions to the given connection as a client.
95 96 97 98 99 |
# File 'lib/protocol/websocket/extensions.rb', line 95 def apply(connection) @accepted.each do |(klass, )| klass.client(connection, **) end end |
#named ⇒ Object
Build a lookup table of extensions keyed by their name.
56 57 58 59 60 |
# File 'lib/protocol/websocket/extensions.rb', line 56 def named @extensions.map do |extension| [extension.first::NAME, extension] end.to_h end |
#offer ⇒ Object
Yield extension offer headers for each registered extension.
65 66 67 68 69 70 71 |
# File 'lib/protocol/websocket/extensions.rb', line 65 def offer @extensions.each do |extension, | if header = extension.offer(**) yield header end end end |