Class: Mongrel2::WebSocket::Request

Inherits:
Request
  • Object
show all
Includes:
FrameMethods
Defined in:
lib/mongrel2/websocket.rb

Overview

WebSocket request – this is the container for Frames from a client.

Instance Attribute Summary

Attributes included from FrameMethods

#frame

Attributes inherited from Request

#body, #conn_id, #headers, #path, #raw, #sender_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FrameMethods

#<<, #inspect_details

Methods inherited from Request

#extended_reply?, #inspect, #is_disconnect?, parse, register_request_type, #remote_ip, #server_chroot, #socket_id, subclass_for_method, #upload_done?, #upload_headers_match?, #upload_started?, #uploaded_file, #valid_upload?

Constructor Details

#initializeRequest

Init a few instance variables unique to websocket requests/responses.



346
347
348
349
350
351
352
353
# File 'lib/mongrel2/websocket.rb', line 346

def initialize( * )
  super

  payload = self.body.read
  self.body.rewind

  @frame = Mongrel2::WebSocket::Frame.new( payload, self.headers.flags )
end

Class Method Details

.response_classObject

Override the type of response returned by this request type.



340
341
342
# File 'lib/mongrel2/websocket.rb', line 340

def self::response_class
  return Mongrel2::WebSocket::Response
end

Instance Method Details

#response(payload = nil, *flags) ⇒ Object

Create a frame in response to the receiving Frame (i.e., with the same Mongrel2 connection ID and sender).



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/mongrel2/websocket.rb', line 358

def response( payload=nil, *flags )
  res = super()

  if payload.is_a?( Symbol ) || payload.is_a?( Integer )
    flags.unshift( payload )
    payload = nil
  end

  if payload
    res.payload.truncate( 0 )
    res.payload << payload
  end
  res.set_flags( *flags ) unless flags.empty?

  return res
end