From: Maksim Melnikau Date: 2008-11-08T20:28:22+09:00 Subject: [ruby-core:19739] [Bug #724] webrick httpresponse wrong content-length Bug #724: webrick httpresponse wrong content-length http://redmine.ruby-lang.org/issues/show/724 Author: Maksim Melnikau Status: Open, Priority: Normal Category: lib, Target version: 1.9.x Webrick(httpresponse) fills HTTP response body with wrong content-type. ---- my variant of fix ---- --- lib/webrick/httpresponse.rb (revision 20147) +++ lib/webrick/httpresponse.rb (working copy) @@ -142,7 +142,7 @@ @header.delete('content-length') elsif @header['content-length'].nil? unless @body.is_a?(IO) - @header['content-length'] = @body ? @body.size : 0 + @header['content-length'] = @body ? @body.bytesize : 0 end end ----- sample webrick-based http server---- #!/usr/bin/ruby19 # coding : utf-8 require 'webrick' include WEBrick hello_proc = lambda do |req, resp| resp['Content-Type'] = "text/html" resp.body = %{ ������������, Rails!

������������, Rails!

������������ Mon Jan 28 14:14:13 +0200 2008

�������������� ���������� ����������������������!

} end hello = HTTPServlet::ProcHandler.new(hello_proc) s = HTTPServer.new(:Port => 3000) s.mount("/", hello) trap("INT"){ s.shutdown } s.start ---- testing with wget ---- max_posedon@localhost ~ % wget http://0.0.0.0:3000 -O - --03:48:01-- http://0.0.0.0:3000/ => `-' Connecting to 0.0.0.0:3000... connected. HTTP request sent, awaiting response... 200 OK Length: 318 [text/html] 0% [ ] 0 --.--K/s ������������, Rails!

������������, Rails!

������������ Mon Jan 28 14:14:13 +0200 2008

�������������� ���������� 100%[====================================================================================================================>] 318 --.--K/s 03:48:01 (10.49 MB/s) - `-' saved [318/318] ---- not hole document downloaded! ---- ---------------------------------------- http://redmine.ruby-lang.org