WEBrick HTTPRequest#to_s should never fail, but does

While experimenting with XmlHttpRequest, I wanted to dump my req

[snip code]
def do_POST(req, res)
  puts "req=#{req.to_s}" # BOOM, HTTPStatus::LengthRequired occured.
[snip code]

IMO, #to_s should never fail.

I think its related to a bad Content-Length:, but is not sure since its
difficult to debug when #to_s fails.

PS. http://www.webrick.org/ seems to be down?

···

--
Simon Strandgaard
btw: thanks, WEBrick is the best.

Is anyone getting this?

Is there a specific WEBrick mailinglist ?

Where should I report WEBrick issues ?

···

--
Simon Strandgaard

In message <200411271509.58571.neoneye@adslhome.dk>,

While experimenting with XmlHttpRequest, I wanted to dump my req

[snip code]
def do_POST(req, res)
  puts "req=#{req.to_s}" # BOOM, HTTPStatus::LengthRequired occured.
[snip code]

IMO, #to_s should never fail.

I think its related to a bad Content-Length:, but is not sure since its
difficult to debug when #to_s fails.

HTTPRequest#raw_header may be useful for this purpose.

  def do_POST(req, res)
    p req.request_line
    req.raw_header.each{|h| p h }
    ...
  end

I'm sorry to post this too late.

···

`Simon Strandgaard <neoneye@adslhome.dk>' wrote:

--
gotoyuzo

In message <200411271509.58571.neoneye@adslhome.dk>,

[snip]

> IMO, #to_s should never fail.

[snip]

HTTPRequest#raw_header may be useful for this purpose.

I'm sorry to post this too late.

Ok, I will check out #raw_header, it sounds useful.

What is your opinion on the policy for #to_s, do you think its good or
bad that it fails ?
(sorry for this direct question)

···

On Tue, 30 Nov 2004 03:35:48 +0900, GOTOU Yuuzou <gotoyuzo@notwork.org> wrote:

`Simon Strandgaard <neoneye@adslhome.dk>' wrote:

--
Simon Strandgaard

Simon Strandgaard ha scritto:

Is anyone getting this?

Is there a specific WEBrick mailinglist ?

well there is http://www.webrick.org/#ml

people read it even if posting rate is quite low.

In message <df1390cc04112911222b5cb6af@mail.gmail.com>,

···

`Simon Strandgaard <neoneye@gmail.com>' wrote:

What is your opinion on the policy for #to_s, do you think its good or
bad that it fails ?

I think it's unavoidable for the incorrect messages.
Of course it should be fixed if it's a bug.

--
gotoyuzo

Ok, I should have told you that im dealing want to deal
with incorrect messages.

Konqueror 3.3.1's XMLHttpRequest sends a "Context-Length: xyz\n\n"
in the body, instead of the header. On the server I correct the message
before processing it. It was difficult to get working because I couldn't
inspect the contents of the broken request.

You can read more about this problem, here:
http://lists.kde.org/?l=kfm-devel&m=110139670817086&w=2

I do something ala this:

if req["user-agent"] =~ /Konqueror\/3.3/
      puts "Workaround for Konqueror/3.3"
      # Konqueror 3.3.1 sends a response with two extra lines..
      # containing "Content-Length: 12345\n\n"
      # This code gets rid of them
      socket = req.instance_variable_get("@socket")
      removed = req.send(:read_line, socket)
      removed += req.send(:read_line, socket)
      m = removed.match(/\AContent-Length: (\d+)/)
      unless m
        raise WEBrick::HTTPStatus::Forbidden, "Konqueror/3.3
workaround failed, wrong content-length syntax"
      end
      cl = m[1]
      puts "content-length=#{cl} removed=#{removed.inspect}"
      unless req.header
        raise WEBrick::HTTPStatus::Forbidden, "Konqueror/3.3
workaround failed, no header"
      end
      req.header["content-length"] = [cl]
    end

Even though this is a bit dirty, I still think that #to_s should never fail.

Sorry for this, Thanks for WEBrick.

···

On Tue, 30 Nov 2004 08:12:29 +0900, GOTOU Yuuzou <gotoyuzo@notwork.org> wrote:

In message <df1390cc04112911222b5cb6af@mail.gmail.com>,
`Simon Strandgaard <neoneye@gmail.com>' wrote:
> What is your opinion on the policy for #to_s, do you think its good or
> bad that it fails ?

I think it's unavoidable for the incorrect messages.
Of course it should be fixed if it's a bug.

--
Simon Strandgaard