Class: Protocol::WebSocket::Extensions::Server
- Inherits:
-
Object
- Object
- Protocol::WebSocket::Extensions::Server
- Defined in:
- lib/protocol/websocket/extensions.rb
Overview
Manages extensions on the server side, negotiating client offers and applying the agreed extensions.
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 supported extensions.(listofsupportedextensions.) ⇒ Object readonly
Class Method Summary collapse
-
.default ⇒ Object
Create a default server with permessage-deflate compression enabled.
Instance Method Summary collapse
-
#accept(headers) ⇒ Object
Negotiate client extension offers and yield accepted response headers.
-
#apply(connection) ⇒ Object
Apply all accepted extensions to the given connection as a server.
-
#initialize(extensions) ⇒ Server
constructor
Initialize a new server extension manager.
-
#named ⇒ Object
Build a lookup table of extensions keyed by their name.
Constructor Details
#initialize(extensions) ⇒ Server
Initialize a new server extension manager.
114 115 116 117 |
# File 'lib/protocol/websocket/extensions.rb', line 114 def initialize(extensions) @extensions = extensions @accepted = [] end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
122 123 124 |
# File 'lib/protocol/websocket/extensions.rb', line 122 def accepted @accepted end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
120 121 122 |
# File 'lib/protocol/websocket/extensions.rb', line 120 def extensions @extensions end |
#The extensions accepted after negotiation.(extensionsacceptedafternegotiation.) ⇒ Object (readonly)
122 |
# File 'lib/protocol/websocket/extensions.rb', line 122 attr :accepted |
#The list of supported extensions.(listofsupportedextensions.) ⇒ Object (readonly)
120 |
# File 'lib/protocol/websocket/extensions.rb', line 120 attr :extensions |
Class Method Details
.default ⇒ Object
Create a default server with permessage-deflate compression enabled.
106 107 108 109 110 |
# File 'lib/protocol/websocket/extensions.rb', line 106 def self.default self.new([ [Extension::Compression, {}] ]) end |
Instance Method Details
#accept(headers) ⇒ Object
Negotiate client extension offers and yield accepted response headers.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/protocol/websocket/extensions.rb', line 137 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
Apply all accepted extensions to the given connection as a server.
166 167 168 169 170 |
# File 'lib/protocol/websocket/extensions.rb', line 166 def apply(connection) @accepted.reverse_each do |(klass, )| klass.server(connection, **) end end |
#named ⇒ Object
Build a lookup table of extensions keyed by their name.
126 127 128 129 130 |
# File 'lib/protocol/websocket/extensions.rb', line 126 def named @extensions.map do |extension| [extension.first::NAME, extension] end.to_h end |