class Async::HTTP::Protocol::HTTP11
def write_body(body, chunked = true)
def write_body(body, chunked = true) if body.nil? or body.empty? @stream.write("Content-Length: 0\r\n\r\n") body.read if body elsif length = body.length @stream.write("Content-Length: #{length}\r\n\r\n") body.each do |chunk| @stream.write(chunk) end elsif chunked @stream.write("Transfer-Encoding: chunked\r\n\r\n") body.each do |chunk| next if chunk.size == 0 @stream.write("#{chunk.bytesize.to_s(16).upcase}\r\n") @stream.write(chunk) @stream.write(CRLF) @stream.flush end @stream.write("0\r\n\r\n") else body = Body::Buffered.for(body) @stream.write("Content-Length: #{body.bytesize}\r\n\r\n") body.each do |chunk| @stream.write(chunk) end end @stream.flush end