summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormakoto kuwata <kwa@kuwata-lab.com>2010-06-27 22:09:31 +0900
committermakoto kuwata <kwa@kuwata-lab.com>2010-06-27 22:18:06 +0900
commitb49df828fa9faef2a1f093392625408f3708b1f8 (patch)
treeacffa68de6810b8a9e8f9b18138cd495e0e37551
parent7e21d861dd46cc52a02dbebdb9eb7dfbe31f963a (diff)
downloaderubis-b49df828fa9faef2a1f093392625408f3708b1f8.tar.gz
[change] change 'contrib/index.cgi' to allow to set @encoding
-rw-r--r--contrib/index.cgi11
1 files changed, 6 insertions, 5 deletions
diff --git a/contrib/index.cgi b/contrib/index.cgi
index fa2014d..d740e4e 100644
--- a/contrib/index.cgi
+++ b/contrib/index.cgi
@@ -10,7 +10,7 @@ require 'erubis'
include Erubis::XmlHelper
ERUBY = Erubis::Eruby # or Erubis::EscapeEruby
-encoding = 'utf-8'
+@encoding = nil
## helper class to represent http error
class HttpError < Exception
@@ -23,7 +23,6 @@ end
## main
-content_type_header = "Content-Type: text/html; charset=#{encoding}\r\n"
begin
## check environment variables
@@ -42,7 +41,9 @@ begin
eruby = ERUBY.load_file(filepath) # or ERUBY.new(File.read(filepath))
html = eruby.result()
## send response
- print content_type_header
+ print @encoding \
+ ? "Content-Type: text/html; charset=#{@encoding}\r\n" \
+ : "Content-Type: text/html\r\n"
print "Content-Length: #{html.length}\r\n"
print "\r\n"
print html
@@ -50,7 +51,7 @@ begin
rescue HttpError => ex
## handle http error (such as 404 Not Found)
print "Status: #{ex.status}\r\n"
- print content_type_header
+ print "Content-Type: text/html\r\n"
print "\r\n"
print "<h2>#{h(ex.status)}</h2>\n"
print "<p>#{h(ex.message)}</p>"
@@ -58,7 +59,7 @@ rescue HttpError => ex
rescue Exception => ex
## print exception backtrace
print "Status: 500 Internal Server Error\r\n"
- print content_type_header
+ print "Content-Type: text/html\r\n"
print "\r\n"
arr = ex.backtrace
print "<pre>\n"