Ruby Apache CGI Premature End of Script Headers

I am trying to do a simple redirect job. I got everything else to work fine. For example, this works:

#!/usr/bin/env ruby

puts "Content-type: text/html"
puts
puts "<h1>blah</h1>"

But this will not work (this is where I get the error “Premature end of script error”):

#!/usr/bin/env ruby

puts "Status: 302 Found"
puts "Content-type: text/html"
puts "Location: http://google.com"

All the other sentences that I found say that this is probably something related to the #!/usr/bin/env rubyscript part , but that does not make any sense to me, since it works with the first example. Any suggestions?

Apache seems to be parsing the headers that I am returning from the cgi script. Is there any way to disable this?

+3
source share
1 answer

You forgot the end puts.

#!/usr/bin/env ruby

puts "Status: 302 Found"
puts "Content-type: text/html"
puts "Location: http://google.com"
puts
+2
source

Source: https://habr.com/ru/post/1755826/


All Articles