Class: WEBrick::HTTPResponse::ChunkedWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/webrick/httpresponse.rb

Instance Method Summary collapse

Constructor Details

#initialize(socket, resp) ⇒ ChunkedWrapper

Returns a new instance of ChunkedWrapper.



556
557
558
559
# File 'lib/webrick/httpresponse.rb', line 556

def initialize(socket, resp)
  @socket = socket
  @resp = resp
end

Instance Method Details

#<<(*buf) ⇒ Object



574
575
576
577
# File 'lib/webrick/httpresponse.rb', line 574

def <<(*buf)
  write(buf)
  self
end

#write(buf) ⇒ Object



561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/webrick/httpresponse.rb', line 561

def write(buf)
  return 0 if buf.empty?
  socket = @socket
  @resp.instance_eval {
    size = buf.bytesize
    data = +"#{size.to_s(16)}#{CRLF}#{buf}#{CRLF}"
    socket.write(data)
    data.clear
    @sent_size += size
    size
  }
end