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.
45 46 47 48 |
# File 'lib/protocol/websocket/extensions.rb', line 45 def initialize(extensions = []) @extensions = extensions @accepted = [] end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
53 54 55 |
# File 'lib/protocol/websocket/extensions.rb', line 53 def accepted @accepted end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
51 52 53 |
# File 'lib/protocol/websocket/extensions.rb', line 51 def extensions @extensions end |
#The extensions accepted after negotiation.(extensionsacceptedafternegotiation.) ⇒ Object (readonly)
53 |
# File 'lib/protocol/websocket/extensions.rb', line 53 attr :accepted |
#The list of extensions to offer.(listofextensionstooffer.) ⇒ Object (readonly)
51 |
# File 'lib/protocol/websocket/extensions.rb', line 51 attr :extensions |
Class Method Details
.default ⇒ Object
Create a default client with permessage-deflate compression enabled.
37 38 39 40 41 |
# File 'lib/protocol/websocket/extensions.rb', line 37 def self.default self.new([ [Extension::Compression, {}] ]) end |
Instance Method Details
#accept(headers) ⇒ Object
Accept server extension responses and record the negotiated extensions.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/protocol/websocket/extensions.rb', line 77 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.
96 97 98 99 100 |
# File 'lib/protocol/websocket/extensions.rb', line 96 def apply(connection) @accepted.each do |(klass, )| klass.client(connection, **) end end |
#named ⇒ Object
Build a lookup table of extensions keyed by their name.
57 58 59 60 61 |
# File 'lib/protocol/websocket/extensions.rb', line 57 def named @extensions.map do |extension| [extension.first::NAME, extension] end.to_h end |
#offer ⇒ Object
Yield extension offer headers for each registered extension.
66 67 68 69 70 71 72 |
# File 'lib/protocol/websocket/extensions.rb', line 66 def offer @extensions.each do |extension, | if header = extension.offer(**) yield header end end end |