Class: CGIEmu::EnvTable
- Inherits:
-
Object
- Object
- CGIEmu::EnvTable
- Defined in:
- lib/cuca/cgi_emu.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(options) ⇒ EnvTable
constructor
A new instance of EnvTable.
- #query_string ⇒ Object
- #the_env_table ⇒ Object
Constructor Details
#initialize(options) ⇒ EnvTable
Returns a new instance of EnvTable.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cuca/cgi_emu.rb', line 13 def initialize() @test_path_info = ['PATH_INFO'] || '/' @test_query_params = ['QUERY_PARAMS'] || {} @request_method = ['REQUEST_METHOD'] || 'GET' @content_length = ['CONTENT_LENGTH'] || 0 @http_cookie = ['HTTP_COOKIE'] the_env_table.each_pair { |k,v| ENV[k] = v.to_s } # ENV.merge(the_env_table) end |
Instance Method Details
#[](key) ⇒ Object
60 61 62 63 |
# File 'lib/cuca/cgi_emu.rb', line 60 def [](key) # $stderr.puts "get FROM ENV_TABLE(#{key}) ==> #{the_env_table[key]}" return the_env_table[key] || nil end |
#query_string ⇒ Object
25 26 27 28 29 |
# File 'lib/cuca/cgi_emu.rb', line 25 def query_string r = [] @test_query_params.each_pair { |k,v| r << "#{k}=#{v}" } return r.join('&') end |
#the_env_table ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cuca/cgi_emu.rb', line 32 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_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"=>@request_method, "HTTP_CONNECTION"=>"Keep-Alive", "CONTENT_LENGTH" => @content_length, "HTTP_COOKIE" => @http_cookie, # 'CONTENT_TYPE' => "application/x-www-form-urlencoded" } end |