Class: WEBrick::HTTPResponse
- Inherits:
-
Object
- Object
- WEBrick::HTTPResponse
- Defined in:
- lib/perfmonger/command/server.rb
Overview
monkey patching HTTPResponse for server-sent events
Constant Summary collapse
- CRLF =
"\r\n"
Instance Method Summary collapse
Instance Method Details
#send_body_io(socket) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/perfmonger/command/server.rb', line 13 def send_body_io(socket) begin if @request_method == "HEAD" # do nothing elsif chunked? begin buf = '' data = '' while true @body.readpartial( @buffer_size, buf ) # there is no need to clear buf? data << format("%x", buf.bytesize) << CRLF data << buf << CRLF _write_data(socket, data) data.clear @sent_size += buf.bytesize end rescue EOFError # do nothing rescue IOError # do nothing end _write_data(socket, "0#{CRLF}#{CRLF}") else size = @header['content-length'].to_i _send_file(socket, @body, 0, size) @sent_size = size end ensure begin; @body.close; rescue IOError; end end end |