WEBrick/Premature end of script headers:

T

Tadeusz Bochan

Hi,
I have been playing around with WEBrick, and kept getting the "Internal
Server Error 500/Premature end of script headers:"
when trying to execute a cgi script.
(This is Ruby 1.8.6 on an HPUX box)

Eventually, I tracked the source of the error down to 'cgihandler.rb',
and resolved the problem by making sure that my cgi script output a "\n"
as the first character. Problem solved, no big deal.

However, I was wondering if anybody else thought the code in
cgihandler.rb
was somewhat questionable.

In the snippet below, the data.split line removes leading \n and then
crashes with the 500 error if there were none.
So that raw_header will always be "".
The code following then goes ahead and parses raw_header anyway.
I get the feeling the code intent was something different.
Am I missing something ? Any opinions ?
Tad

... (snippet from cgihandler.rb) ...
data = "" unless data
raw_header, body = data.split(/^[\xd\xa]+/on, 2) #remove leading \n ?
Why ?
raise HTTPStatus::InternalServerError,
"Premature end of script headers: #{@script_filename}" if body.nil?
begin
header = HTTPUtils::parse_header(raw_header)
if /^(\d+)/ =~ header['status'][0]
res.status = $1.to_i
header.delete('status')
end
if header.has_key?('set-cookie')
...
 

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

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top