0
+require 'rails_adapter'
0
+rails_root = '/Users/tom/dev/mojombo/helloworld'
0
+require File.join(rails_root, 'config/boot')
0
+require RAILS_ROOT + "/config/environment"
0
+$logger = Logger.new(RAILS_ROOT + "/log/fuzed.#{Process.pid}.log")
0
+$app = Rack::Adapter::Rails.new(:root => RAILS_ROOT)
0
+ method = request[:method]
0
+ version = request[:http_version] # => e.g. [1, 1]
0
+ path = request[:querypath]
0
+ query = request[:querydata] == :undefined ? '' : request[:querydata]
0
+ server = request[:servername]
0
+ headers = request[:headers]
0
+ cookies = request[:cookies]
0
+ postdata = request[:postdata] == :undefined ? '' : request[:postdata]
0
+ translate = {:content_type => 'CONTENT_TYPE',
0
+ :content_length => 'CONTENT_LENGTH',
0
+ :accept => 'HTTP_ACCEPT',
0
+ :'Accept-Charset' => 'HTTP_ACCEPT_CHARSET',
0
+ :'Accept-Encoding' => 'HTTP_ACCEPT_ENCODING',
0
+ :'Accept-Language' => 'HTTP_ACCEPT_LANGUAGE',
0
+ :connection => 'HTTP_CONNECTION',
0
+ :keep_alive => 'HTTP_KEEP_ALIVE',
0
+ :referer => 'HTTP_REFERER',
0
+ :user_agent => 'HTTP_USER_AGENT',
0
+ 'X-Prototype-Version' => 'HTTP_X_PROTOTYPE_VERSION',
0
+ 'X-Requested-With' => 'HTTP_X_REQUESTED_WITH'}
0
+ env['REQUEST_METHOD'] = method.to_s
0
+ env['QUERY_STRING'] = query
0
+ env["PATH_INFO"] = path == '/' ? '' : path
0
+ env = headers.inject(env) { |a, x| a[translate[x[0]] || x[0].to_s] = x[1]; a }
0
+ env.delete_if { |k, v| v.nil? }
0
+ env.update({"rack.version" => [0, 1],
0
+ "rack.input" => StringIO.new(postdata),
0
+ "rack.errors" => STDERR,
0
+ "rack.multithread" => true,
0
+ "rack.multiprocess" => false,
0
+ "rack.run_once" => false,
0
+ "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
0
+ env['SERVER_NAME'] = server.split(':')[0]
0
+ env['SERVER_PORT'] = server.split(':')[1]
0
+ env['HTTP_VERSION'] = version.join('.')
0
+ env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
0
+ env["QUERY_STRING"] ||= ""
0
+ env["REQUEST_PATH"] ||= "/"
0
+ env.delete "PATH_INFO" if env["PATH_INFO"] == ""
0
+ cookies.each do |cookie|
0
+ env["HTTP_COOKIE"] = cookie.to_s
0
+ log('------------IN------------') if LOG
0
+ log(env.inspect) if LOG
0
+ status, headers, body = $app.call(env)
0
+ rails_delta = Time.now - t1
0
+ $rails_avg[0] += rails_delta
0
+ log(">> Rails in #{rails_delta} (#{$rails_avg[0] / $rails_avg[1]} avg) sec") if LOG
0
+ headers['Server'] = 'YAWS + Fuzed 0.0.1'
0
+ headers['Connection'] = 'close'
0
+ cookies = headers.delete('cookie')
0
+ #cookies.map! {|c| c.include?('path=') ? c : c + "; path=/"}
0
+ headers['Set-Cookie'] = cookies if cookies
0
+ status = (headers["Status"].split(" ").first rescue nil) || status
0
+ headers.delete("Status") if headers["Status"]
0
+ [[:status, status.to_i],
0
+ [:allheaders, headers.inject([]) { |a, x| a += x[1].map { |y| [:header, x[0], y] } }],
0
+ [:header, "Content-Type", "text/plain; charset=utf-8"],
0
+ [:header, "Cache-Control", "no-cache"]]],
0
+ [:html, "500 Internal Error\n\n#{e}\n\n#{e.backtrace}"]]]
0
+ log('-----------OUT------------') if LOG
0
+ log(res.inspect) if LOG
0
+class RailsHandler < Chassis
0
+ details("rails" => "default")
0
+ handle(:handle_request) do |args|
0
+ # [[:method, :POST], [:http_version, [1, 1]], [:querypath, "/main/go"], [:querydata, ""], [:servername, "testing:8002"], [:headers, [[:connection, "keep-alive"], [:accept, "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"], [:host, "localhost:8002"], [:referer, "http://localhost:8002/main/ready"], [:user_agent, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"], [:keep_alive, "300"], [:content_length, "7"], [:content_type, "application/x-www-form-urlencoded"], [:"Cache-Control", "max-age=0"], [:"Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"], [:"Accept-Encoding", "gzip,deflate"], [:"Accept-Language", "en-us,en;q=0.5"]]], [:cookies, ["_helloworld_session_id=d3eae987aab3230377abc433b7a8d7c1"]], [:pathinfo, "/Users/tom/dev/fuzed/helloworld/public"], [:postdata, "val=foo"]]
0
+ :http_version => [1, 1],
0
+ :querypath => "/main/go",
0
+ :servername => "testing:8002",
0
+ :headers => {:connection => "keep-alive",
0
+ :accept => "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
0
+ :host => "localhost:8002",
0
+ :referer => "http://localhost:8002/main/ready",
0
+ :user_agent => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3",
0
+ :content_length => "7",
0
+ :content_type => "application/x-www-form-urlencoded",
0
+ :"Cache-Control" => "max-age=0",
0
+ :"Accept-Charset" => "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
0
+ :"Accept-Encoding" => "gzip,deflate",
0
+ :"Accept-Language" => "en-us,en;q=0.5"},
0
+ :cookies => ["_helloworld_session_id=d3eae987aab3230377abc433b7a8d7c1"],
0
+ :pathinfo => "/Users/tom/dev/fuzed/helloworld/public",
0
+ :postdata => "val=foo"}
0
+ # [[:method, :GET], [:http_version, [1, 1]], [:querypath, "/main/say"], [:querydata, ""], [:servername, "testing:8002"], [:headers, [[:connection, "keep-alive"], [:accept, "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"], [:host, "localhost:8002"], [:user_agent, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"], [:keep_alive, "300"], [:"Cache-Control", "max-age=0"], [:"Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"], [:"Accept-Encoding", "gzip,deflate"], [:"Accept-Language", "en-us,en;q=0.5"]]], [:cookies, ["_helloworld_session_id=166098a3c3f702698d0529c6148c6164"]], [:pathinfo, "/Users/tom/dev/fuzed/helloworld/public"], [:postdata, :undefined]]
Comments
No one has commented yet.