WEBrick HTTPRequest#to_s should never fail, but does

S

Simon Strandgaard

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?
 
S

Simon Strandgaard

Is anyone getting this?

Is there a specific WEBrick mailinglist ?

Where should I report WEBrick issues ?
 
G

GOTOU Yuuzou

In message said:
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.
 
S

Simon Strandgaard

In message <[email protected]>,
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)
 
G

GOTOU Yuuzou

In message said:
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.
 
S

Simon Strandgaard

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top