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.
84 85 86 87 |
# File 'lib/protocol/websocket/extensions.rb', line 84 def initialize(extensions) @extensions = extensions @accepted = [] end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
90 91 92 |
# File 'lib/protocol/websocket/extensions.rb', line 90 def accepted @accepted end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
89 90 91 |
# File 'lib/protocol/websocket/extensions.rb', line 89 def extensions @extensions end |
Class Method Details
.default ⇒ Object
78 79 80 81 82 |
# File 'lib/protocol/websocket/extensions.rb', line 78 def self.default self.new([ [Extension::Compression, {}] ]) end |
Instance Method Details
#accept(headers) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/protocol/websocket/extensions.rb', line 98 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 @accepted << [klass, ] end end end return headers end |
#apply(connection) ⇒ Object
125 126 127 128 129 |
# File 'lib/protocol/websocket/extensions.rb', line 125 def apply(connection) @accepted.reverse_each do |(klass, )| klass.server(connection, **) end end |
#named ⇒ Object
92 93 94 95 96 |
# File 'lib/protocol/websocket/extensions.rb', line 92 def named @extensions.map do |extension| [extension.first::NAME, extension] end.to_h end |