lib/hayabusa_fcgi.rb in hayabusa-0.0.24 vs lib/hayabusa_fcgi.rb in hayabusa-0.0.25
- old
+ new
@@ -11,10 +11,21 @@
@hayabusa_fcgi_conf_path = nil
@fcgi_proxy = nil
@debug = false
end
+ def conf_path
+ #Parse the configuration-header and generate Hayabusa-config-hash.
+ if @cgi.env["HAYABUSA_FCGI_CONFIG"].to_s.length > 0
+ return @cgi.env["HAYABUSA_FCGI_CONFIG"]
+ elsif @cgi.env["HTTP_HAYABUSA_FCGI_CONFIG"].to_s.length > 0
+ return @cgi.env["HTTP_HAYABUSA_FCGI_CONFIG"]
+ else
+ raise "No HTTP_HAYABUSA_FCGI_CONFIG-header was given or HAYABUSA_FCGI_CONFIG environment variable."
+ end
+ end
+
#Evaluates if a new host-process should be started or we should proxy calls to an existing one.
def evaluate_mode
#If this is a FCGI-proxy-instance then the HTTP-connection should be checked if it is working.
if @fcgi_proxy
if !@fcgi_proxy[:http].socket_working?
@@ -23,13 +34,11 @@
end
#Skip the actual check if Hayabusa is spawned or this is a working FCGI-proxy-instance.
return nil if @hayabusa or @fcgi_proxy
- #Parse the configuration-header and generate Hayabusa-config-hash.
- raise "No HTTP_HAYABUSA_FCGI_CONFIG-header was given." if !@cgi.env["HTTP_HAYABUSA_FCGI_CONFIG"]
- @hayabusa_fcgi_conf_path = @cgi.env["HTTP_HAYABUSA_FCGI_CONFIG"]
+ @hayabusa_fcgi_conf_path = conf_path
require @hayabusa_fcgi_conf_path
raise "No 'Hayabusa::FCGI_CONF'-constant was spawned by '#{@cgi.env["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if !Hayabusa.const_defined?(:FCGI_CONF)
conf = Hayabusa::FCGI_CONF
hayabusa_conf = Hayabusa::FCGI_CONF[:hayabusa]
@@ -146,10 +155,10 @@
rescue Errno::EAGAIN
retry
end
#Ensure the same FCGI-process isnt active for more than one website.
- raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{@hayabusa_fcgi_conf_path}' but it wasnt: '#{cgi.env["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if @hayabusa_fcgi_conf_path and @hayabusa_fcgi_conf_path != cgi.env["HTTP_HAYABUSA_FCGI_CONFIG"]
+ raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{@hayabusa_fcgi_conf_path}' but it wasnt: '#{conf_path}' #{@cgi.env}" if @hayabusa_fcgi_conf_path != conf_path
#Proxy request to the host-FCGI-process.
raise "No proxy spawned." unless @fcgi_proxy
$stderr.puts "[hayabusa] Proxying request." if @debug
@cgi_tools.proxy_request_to(:cgi => cgi, :http => @fcgi_proxy[:http], :fp_log => @fcgi_proxy[:fp_log])