examples/ws-echo.rb in mongrel2-0.24.0 vs examples/ws-echo.rb in mongrel2-0.25.0.pre.285
- old
+ new
@@ -2,11 +2,10 @@
# encoding: utf-8
require 'loggability'
require 'pathname'
require 'mongrel2/config'
-require 'mongrel2/logging'
require 'mongrel2/handler'
# An example of a WebSocket (RFC6455) Mongrel2 application that echoes back whatever
# (non-control) frames you send it. It will also ping all of its clients and disconnect
@@ -97,12 +96,13 @@
frame.sender_id,
frame.conn_id,
frame.opcode.to_s.upcase,
frame.fin? ? '' : '(cont)',
frame.headers.x_forwarded_for,
- frame.payload[ 0, 20 ],
+ frame.payload.read( 20 ),
]
+ frame.payload.rewind
# If a client sends an invalid frame, close their connection, but politely.
if !frame.valid?
self.log.error " invalid frame from client: %s" % [ frame.errors.join(';') ]
res = frame.response( :close )
@@ -128,10 +128,10 @@
self.log.info "Echoing data frame: %p" % [ frame ]
# Make the response frame
response = frame.response
response.fin = frame.fin?
- response.payload = frame.payload
+ IO.copy_stream( frame.payload, response.payload )
return response
end
alias_method :handle_binary_frame, :handle_text_frame
alias_method :handle_continuation_frame, :handle_text_frame