Class: CGIEmu::EnvTable

Inherits:
Object
  • Object
show all
Defined in:
lib/cuca/cgi_emu.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ EnvTable

Returns a new instance of EnvTable.



9
10
11
12
13
14
15
16
# File 'lib/cuca/cgi_emu.rb', line 9

def initialize(options)
 @test_path_info = options['PATH_INFO'] || '/'
 @test_query_params = options['QUERY_PARAMS'] || {}

 the_env_table.each_pair { |k,v| ENV[k] = v }

#     ENV.merge(the_env_table)
end

Instance Method Details

#[](key) ⇒ Object



50
51
52
53
# File 'lib/cuca/cgi_emu.rb', line 50

def [](key)
 #     $stderr.puts "get FROM ENV_TABLE(#{key}) ==> #{the_env_table[key]}"
  return the_env_table[key] || nil
end

#query_stringObject



18
19
20
21
22
# File 'lib/cuca/cgi_emu.rb', line 18

def query_string
  r = [] 
  @test_query_params.each_pair { |k,v| r << "#{k}=#{v}" }
  return r.join('&')
end

#the_env_tableObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cuca/cgi_emu.rb', line 25

def the_env_table
 {"SERVER_NAME"=>"localhost", 
 "PATH_INFO"=>@test_path_info,
 "REMOTE_HOST"=>"localhost", 
 "HTTP_ACCEPT_ENCODING"=>"x-gzip, x-deflate, gzip, deflate",
 "HTTP_USER_AGENT"=>"Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.8 (like Gecko)", 
 "SCRIPT_NAME"=>"", 
 "SERVER_PROTOCOL"=>"HTTP/1.1", 
 "HTTP_ACCEPT_LANGUAGE"=>"en", 
 "HTTP_HOST"=>"localhost:2000", 
 "REMOTE_ADDR"=>"127.0.0.1", 
 "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.6/2007-06-07)",
 "HTTP_REFERER"=>"http://localhost:2000/",
 "HTTP_COOKIE"=>"cuca_session=285715682bf030a19cb24b2560aabc36",
 "HTTP_ACCEPT_CHARSET"=>"utf-8, utf-8;q=0.5, *;q=0.5",
 "REQUEST_URI"=>"http://localhost:2000" + @test_path_info, 
 "SERVER_PORT"=>"2000", 
 "GATEWAY_INTERFACE"=>"CGI/1.1", 
 "QUERY_STRING"=>query_string, 
 "HTTP_ACCEPT"=>"text/html, image/jpeg, image/png, text/*, image/*, */*",
 "SCRIPT_FILENAME"=>"/home/bones/workspace/cuca/scripts/../public/dispatch.cgi",
 "REQUEST_METHOD"=>"GET", 
 "HTTP_CONNECTION"=>"Keep-Alive"}
end