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.
115 116 117 118 |
# File 'lib/protocol/websocket/extensions.rb', line 115 def initialize(extensions) @extensions = extensions @accepted = [] end |
Instance Attribute Details
#accepted ⇒ Object (readonly)
Returns the value of attribute accepted.
123 124 125 |
# File 'lib/protocol/websocket/extensions.rb', line 123 def accepted @accepted end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
121 122 123 |
# File 'lib/protocol/websocket/extensions.rb', line 121 def extensions @extensions end |
#The extensions accepted after negotiation.(extensionsacceptedafternegotiation.) ⇒ Object (readonly)
123 |
# File 'lib/protocol/websocket/extensions.rb', line 123 attr :accepted |
#The list of supported extensions.(listofsupportedextensions.) ⇒ Object (readonly)
121 |
# File 'lib/protocol/websocket/extensions.rb', line 121 attr :extensions |
Class Method Details
.default ⇒ Object
Create a default server with permessage-deflate compression enabled.
107 108 109 110 111 |
# File 'lib/protocol/websocket/extensions.rb', line 107 def self.default self.new([ [Extension::Compression, {}] ]) end |
Instance Method Details
#accept(headers) ⇒ Object
Negotiate client extension offers and yield accepted response headers.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/protocol/websocket/extensions.rb', line 138 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[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.
164 165 166 167 168 |
# File 'lib/protocol/websocket/extensions.rb', line 164 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.
127 128 129 130 131 |
# File 'lib/protocol/websocket/extensions.rb', line 127 def named @extensions.map do |extension| [extension.first::NAME, extension] end.to_h end |