Class: Mongrel2::WebSocketRequestFactory
- Inherits:
-
RequestFactory
- Object
- RequestFactory
- Mongrel2::WebSocketRequestFactory
- Includes:
- Constants
- Defined in:
- lib/mongrel2/testing.rb
Overview
A factory for generating WebSocket request objects for testing.
Constant Summary collapse
- DEFAULT_TESTING_HOST =
The default host
'localhost'
- DEFAULT_TESTING_PORT =
'8113'
- DEFAULT_TESTING_ROUTE =
'/ws'
- DEFAULT_TESTING_HEADERS =
Default headers
Mongrel2::Table.new( 'METHOD' => 'WEBSOCKET', 'PATTERN' => '/ws', 'URI' => '/ws', 'VERSION' => 'HTTP/1.1', 'PATH' => '/ws', 'upgrade' => 'websocket', 'host' => DEFAULT_TESTING_HOST, 'sec-websocket-key' => 'rBP9u8uxVvIYrH/8bNOPwQ==', 'sec-websocket-version' => '13', 'connection' => 'Upgrade', 'origin' => "http://#{DEFAULT_TESTING_HOST}", 'FLAGS' => '0x89', # FIN + PING 'x-forwarded-for' => '127.0.0.1' )
- DEFAULT_FACTORY_CONFIG =
The defaults used by the websocket request factory
{ :sender_id => DEFAULT_TEST_UUID, :conn_id => DEFAULT_CONN_ID, :host => DEFAULT_TESTING_HOST, :port => DEFAULT_TESTING_PORT, :route => DEFAULT_TESTING_ROUTE, :headers => DEFAULT_TESTING_HEADERS, }
- DEFAULT_HANDSHAKE_BODY =
'GR7M5bFPiY2GvVc5a7CIMErQ18Q='
Constants included from Constants
Constants::DATA_DIR, Constants::DEFAULT_CONFIG_SCRIPT, Constants::DEFAULT_CONFIG_URI, Constants::DEFAULT_CONTROL_SOCKET, Constants::MAX_BROADCAST_IDENTS
Constants inherited from RequestFactory
RequestFactory::DEFAULT_CONN_ID, RequestFactory::DEFAULT_TESTING_URL, RequestFactory::DEFAULT_TEST_UUID, RequestFactory::TEST_RECV_SPEC, RequestFactory::TEST_SEND_SPEC
Instance Attribute Summary
Attributes inherited from RequestFactory
#conn_id, #headers, #host, #port, #route, #sender_id
Instance Method Summary collapse
-
#binary(uri, payload = '', *flags) ⇒ Object
Create a binary frame.
-
#close(uri, payload = '', *flags) ⇒ Object
Create a close frame.
-
#continuation(uri, payload = '', *flags) ⇒ Object
Create a continuation frame.
-
#create(uri, data, *flags) ⇒ Object
Create a new request with the specified
uri
,data
, andflags
. -
#handshake(uri, *subprotocols) ⇒ Object
Create an initial websocket handshake request and return it.
-
#ping(uri, payload = '', *flags) ⇒ Object
Create a ping frame.
-
#pong(uri, payload = '', *flags) ⇒ Object
Create a pong frame.
-
#text(uri, payload = '', *flags) ⇒ Object
Create a text frame.
Methods inherited from RequestFactory
default_factory_config, default_headers, #delete, #get, #head, #initialize, #options, #post, #put
Constructor Details
This class inherits a constructor from Mongrel2::RequestFactory
Instance Method Details
#binary(uri, payload = '', *flags) ⇒ Object
Create a binary frame.
386 387 388 389 |
# File 'lib/mongrel2/testing.rb', line 386 def binary( uri, payload='', *flags ) flags << :binary return self.create( uri, payload, flags ) end |
#close(uri, payload = '', *flags) ⇒ Object
Create a close frame.
393 394 395 396 |
# File 'lib/mongrel2/testing.rb', line 393 def close( uri, payload='', *flags ) flags << :close << :fin return self.create( uri, payload, flags ) end |
#continuation(uri, payload = '', *flags) ⇒ Object
Create a continuation frame.
372 373 374 375 |
# File 'lib/mongrel2/testing.rb', line 372 def continuation( uri, payload='', *flags ) flags << :continuation return self.create( uri, payload, flags ) end |
#create(uri, data, *flags) ⇒ Object
Create a new request with the specified uri
, data
, and flags
.
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/mongrel2/testing.rb', line 358 def create( uri, data, *flags ) raise "Request doesn't route through %p" % [ self.route ] unless uri.start_with?( self.route ) headers = if flags.last.is_a?( Hash ) then flags.pop else {} end flagheader = make_flags_header( flags ) headers = self.make_merged_headers( uri, flagheader, headers ) rclass = Mongrel2::Request.subclass_for_method( :WEBSOCKET ) return rclass.new( self.sender_id, self.conn_id.to_s, self.route, headers, data ) end |
#handshake(uri, *subprotocols) ⇒ Object
Create an initial websocket handshake request and return it.
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/mongrel2/testing.rb', line 338 def handshake( uri, *subprotocols ) raise "Request doesn't route through %p" % [ self.route ] unless uri.start_with?( self.route ) headers = if subprotocols.last.is_a?( Hash ) then subprotocols.pop else {} end headers = self.make_merged_headers( uri, 0, headers ) headers.delete( :flags ) unless subprotocols.empty? protos = subprotocols.map( &:to_s ).join( ', ' ) headers.sec_websocket_protocol = protos end rclass = Mongrel2::Request.subclass_for_method( :WEBSOCKET_HANDSHAKE ) return rclass.new( self.sender_id, self.conn_id.to_s, self.route, headers, DEFAULT_HANDSHAKE_BODY.dup ) end |
#ping(uri, payload = '', *flags) ⇒ Object
Create a ping frame.
400 401 402 403 |
# File 'lib/mongrel2/testing.rb', line 400 def ping( uri, payload='', *flags ) flags << :ping << :fin return self.create( uri, payload, flags ) end |
#pong(uri, payload = '', *flags) ⇒ Object
Create a pong frame.
407 408 409 410 |
# File 'lib/mongrel2/testing.rb', line 407 def pong( uri, payload='', *flags ) flags << :pong << :fin return self.create( uri, payload, flags ) end |
#text(uri, payload = '', *flags) ⇒ Object
Create a text frame.
379 380 381 382 |
# File 'lib/mongrel2/testing.rb', line 379 def text( uri, payload='', *flags ) flags << :text return self.create( uri, payload, flags ) end |