Class: Protocol::WebSocket::Extensions::Server
- Inherits:
-
Object
- Object
- Protocol::WebSocket::Extensions::Server
- 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) ⇒ Server
constructor
A new instance of Server.
- #named ⇒ Object
Constructor Details
#initialize(extensions) ⇒ Server
Returns a new instance of Server.
86 87 88 89 |
# File 'lib/protocol/websocket/extensions.rb', line 86 def initialize(extensions) @extensions = extensions @accepted = [] end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
92 93 94 |
# File 'lib/protocol/websocket/extensions.rb', line 92 def accepted @accepted end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
91 92 93 |
# File 'lib/protocol/websocket/extensions.rb', line 91 def extensions @extensions end |
Class Method Details
.default ⇒ Object
80 81 82 83 84 |
# File 'lib/protocol/websocket/extensions.rb', line 80 def self.default self.new([ [Extension::Compression, {}] ]) end |
Instance Method Details
#accept(headers) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/protocol/websocket/extensions.rb', line 100 def accept(headers) extensions = [] named = self.named response = [] # Each response header should map to at least one extension. Extensions.parse(headers) do |name, arguments| if extension = named[name] klass, = extension if result = klass.negotiate(arguments, **) header, = result # The extension is accepted and no further offers will be considered: named.delete(name) yield header if block_given? @accepted << [klass, ] end end end return @accepted end |
#apply(connection) ⇒ Object
127 128 129 130 131 |
# File 'lib/protocol/websocket/extensions.rb', line 127 def apply(connection) @accepted.reverse_each do |(klass, )| klass.server(connection, **) end end |
#named ⇒ Object
94 95 96 97 98 |
# File 'lib/protocol/websocket/extensions.rb', line 94 def named @extensions.map do |extension| [extension.first::NAME, extension] end.to_h end |