59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/baykit/bayserver/util/cgi_util.rb', line 59
def self.get_env(path, doc_root, script_base, tur, &block)
= tur.req.
ctype = .content_type
if StringUtil.set? ctype
pos = ctype.index("charset=")
if pos != nil && pos >= 0
tur.req.charset = ctype[pos+8 .. -1].strip
end
end
add_env(REQUEST_METHOD, tur.req.method, &block)
add_env(REQUEST_URI, tur.req.uri, &block)
add_env(SERVER_PROTOCOL, tur.req.protocol, &block)
add_env(GATEWAY_INTERFACE, "CGI/1.1", &block)
add_env(SERVER_NAME, tur.req.req_host, &block)
add_env(SERVER_ADDR, tur.req.server_address, &block)
if tur.req.req_port >= 0
add_env(SERVER_PORT, tur.req.req_port, &block)
end
add_env(SERVER_SOFTWARE, BayServer.get_software_name, &block)
add_env(CONTEXT_DOCUMENT_ROOT, doc_root, &block)
tur.req..names.each do |name|
newval = nil
tur.req..values(name).each do |value|
if newval == nil
newval = value
else
newval = newval + "; " + value
end
end
name = name.upcase.tr('-', '_')
if name.start_with?("X_FORWARDED_")
add_env(name, newval, &block)
else
case name
when CONTENT_TYPE, CONTENT_LENGTH
add_env(name, newval, &block)
else
add_env("HTTP_" + name, newval, &block)
end
end
end
add_env(REMOTE_ADDR, tur.req.remote_address, &block)
add_env(REMOTE_PORT, tur.req.remote_port, &block)
add_env(REQUEST_SCHEME, tur.is_secure ? "https": "http", &block)
tmp_secure = tur.is_secure
fproto = tur.req..get(Headers::X_FORWARDED_PROTO)
if fproto != nil
tmp_secure = fproto.casecmp?("https")
end
if tmp_secure
add_env(HTTPS, "on", &block)
end
add_env(QUERY_STRING, tur.req.query_string, &block)
add_env(SCRIPT_NAME, tur.req.script_name, &block)
add_env(UNIQUE_ID, DateTime.now.to_s, &block)
if tur.req.path_info == nil
add_env(PATH_INFO, "", &block)
else
add_env(PATH_INFO, tur.req.path_info, &block)
locpath = doc_root
if locpath.end_with? "/"
locpath = locpath[0 .. -2]
end
path_translated = locpath + tur.req.path_info
add_env(PATH_TRANSLATED, path_translated, &block)
end
if !script_base.end_with?("/")
script_base = script_base + "/"
end
add_env(SCRIPT_FILENAME, "#{script_base}#{tur.req.script_name[path.length .. -1]}", &block)
add_env(PATH, ENV["PATH"], &block)
end
|