lib/scripts/knjappserver_cgi.rb in knjappserver-0.0.28 vs lib/scripts/knjappserver_cgi.rb in knjappserver-0.0.29
- old
+ new
@@ -41,14 +41,23 @@
return post_hash
end
end
+require "knjrbfw"
+
begin
- require "knj/autoload"
- require "#{File.dirname(Knj::Os.realpath(__FILE__))}/../knjappserver.rb"
+ require "http2"
+ require "tsafe"
+ #Read real path.
+ file = __FILE__
+ file = File.readlink(file) if File.symlink?(file)
+ file = File.realpath(file)
+
+ require "#{File.dirname(file)}/../knjappserver.rb"
+
raise "No HTTP_KNJAPPSERVER_CGI_CONFIG-header was given." if !ENV["HTTP_KNJAPPSERVER_CGI_CONFIG"]
require ENV["HTTP_KNJAPPSERVER_CGI_CONFIG"]
begin
conf = Knjappserver::CGI_CONF
@@ -78,11 +87,11 @@
#The rest is copied from the FCGI-part.
headers = {}
cgi.env_table.each do |key, val|
if key[0, 5] == "HTTP_" and key != "HTTP_KNJAPPSERVER_CGI_CONFIG"
- key = Knj::Php.ucwords(key[5, key.length].gsub("_", " ")).gsub(" ", "-")
+ key = key[5, key.length].gsub("_", " ").gsub(" ", "-")
headers[key] = val
end
end
#Make request.
@@ -107,38 +116,39 @@
:cookies => false,
:on_content => proc{|line|
cgi.print(line) if count > 0
count += 1
}
- })
+ )
elsif cgi.request_method == "POST"
count = 0
http.post(:url => url, :post => Knjappserver.convert_fcgi_post(cgi.params),
:default_headers => headers,
:cookies => false,
:on_content => proc{|line|
cgi.print(line) if count > 0
count += 1
}
- })
+ )
else
count = 0
- http.get(url, {
+ http.get(
+ :url => url,
:default_headers => headers,
:cookies => false,
:on_content => proc{|line|
cgi.print(line) if count > 0
count += 1
}
- })
+ )
end
rescue Exception => e
print "Content-Type: text/html\r\n"
print "\n\n"
print Knj::Errors.error_str(e, {:html => true})
begin
knjappserver.stop if knjappserver
rescue => e
- print "<br />\n<br />\n" + Knj::Errors.error_str(e, {:html => true})
+ print "<br />\n<br />\n#{Knj::Errors.error_str(e, {:html => true})}"
end
end
\ No newline at end of file