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:arse_header(raw_header)
if /^(\d+)/ =~ header['status'][0]
res.status = $1.to_i
header.delete('status')
end
if header.has_key?('set-cookie')
...
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:arse_header(raw_header)
if /^(\d+)/ =~ header['status'][0]
res.status = $1.to_i
header.delete('status')
end
if header.has_key?('set-cookie')
...