Project

General

Profile

Actions

Bug #724

closed

webrick httpresponse wrong content-length

Added by max_posedon (Maksim Melnikau) over 15 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
Backport:
[ruby-core:19739]

Description

=begin
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 = %{


<title> Привет, Rails! </title>


Привет, 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


<title> Привет, Rails! </title>


Привет, 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! ----
=end

Actions

Also available in: Atom PDF

Like0
Like0