def initialize(request=nil)
unless request
request = Apache.request if ENV['MOD_RUBY']
end
if request
@hostname = request.hostname
@unparsed_uri = request.unparsed_uri
@uri = request.uri
@filename = request.filename
@request_time = request.request_time
@request_method = request.request_method
@header_only = request.header_only?
@args = request.args
@args = '' if args.nil?
@content_type = request.content_type
@content_encoding = request.content_encoding
@content_languages = request.content_languages
@remote_host = request.remote_host
@auth_type = request.auth_type
@auth_name = request.auth_name
@cache_resp = request.cache_resp
@content = ''
@params = Hash.new
if @args.to_s != ''
@args.split('&').each do |a|
k,v = a.split('=',2).collect{|x| unescape(x)}
if @params.has_key? k
@params[k] += "\0" + (v or "")
else
@params[k] = (v or "")
end
end
else
if m = MIMERegexp.match(request.headers_in['Content-Type'])
boundary = m[1]
@params = read_multipart(boundary,request.headers_in['Content-Length'],request)
else
@content = $stdin.read
@content = '' if @content.nil?
@content.split(/[&;]/).each do |x|
key, val = x.split(/=/,2).collect{|x| unescape(x)}
if @params.include?(key)
@params[key] += "\0" + (val or "")
else
@params[key] = (val or "")
end
end
end
end
@headers_in = Iowa::R::Table.new
request.headers_in.each do |key,value|
@headers_in[key] = value
end
@status_line = request.status_line
@headers_out = Iowa::R::Table.new
request.headers_out.each do |key,value|
@headers_out[key] = value
end
else
@hostname = ENV['SERVER_NAME']
@unparsed_uri = nil
@uri = ENV['REQUEST_URI']
@filename = ENV['SCRIPT_FILENAME']
@request_time = Time.now.asctime
@request_method = ENV['REQUEST_METHOD']
@remote_host = ENV['REMOTE_HOST']
@headers_only = (@request_method.to_s == 'HEAD') ? true : false
c = CGI.new
@params = c.params
@params.each_pair do |k,v|
if (v.class.to_s == 'StringIO') or (v.class.to_s == 'Tempfile')
@params[k] = Iowa::FileData.new(v.original_filename,v.content_type,v.read)
end
end
@args = @request_method == 'POST' ? '' : @params.keys.collect {|i| "#{i}=#{@params[i]}"}.join('&')
@headers_in = Iowa::R::Table.new
ENV.each do |k,v|
key = k.dup
value = v.dup
next unless key =~ /^HTTP_/
key.sub!(/^HTTP_/,'')
key.gsub!(/([^_]+_?)/) do |s|
s.capitalize
end
@headers_in[key] = value
end
@status_line = nil
@headers_out = Iowa::R::Table.new
@content_type = nil
@content_encoding = nil
@content_languages = nil
@content = ''
end
end