Created
April 29, 2010 17:11
-
-
Save takeru/383903 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| puts "it is dummy.rb" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'appengine-rack' | |
| AppEngine::Rack.configure_app( | |
| :application => "rack20100430-023242", | |
| :precompilation_enabled => true, | |
| :version => "1") | |
| #ENV['RACK_ENV'] = AppEngine::Rack.environment | |
| if true | |
| s = File.lstat("/Users") ## <<<<<<<<<<<<<<<<<<<<<< SUCCESS | |
| p ["A:", s] | |
| ## ["A:", #<File::Stat dev=0xino=0, mode=040644, nlink=uid=-1, gid=rdev=0xsize=306, blksize=4096, blocks=atime=Sun Apr 18 08:21:50 UTC 2010, mtime=Sun Apr 18 08:21:50 UTC 2010, ctime=Mon Apr 26 03:56:45 UTC 2010>] | |
| class DeferredDispatcher2 | |
| def initialize args | |
| p ["[initialize]", "args", args] | |
| @args = args | |
| end | |
| def call env | |
| p ["[call]", "@runtime", @runtime, "@rack_app", @rack_app] | |
| s = File.lstat("/Users") ## <<<<<<<<<<<<<<<<<<<<<< FAIL | |
| ## => `call': No such file or directory - /Users (Errno::ENOENT) | |
| p ["B:", s] | |
| if @runtime.nil? | |
| @runtime = true | |
| # 1: redirect with runtime and jruby-rack loaded | |
| redirect_or_error(env) | |
| elsif @rack_app.nil? | |
| require @args[:require] | |
| @rack_app = Object.module_eval(@args[:dispatch]).new | |
| # 2: redirect with framework required & dispatched | |
| redirect_or_error(env) | |
| else | |
| # 3: process all other requests | |
| @rack_app.call(env) | |
| end | |
| end | |
| def redirect_or_error(env) | |
| if env['REQUEST_METHOD'].eql?('GET') | |
| redir_url = env['REQUEST_URI'] + | |
| (env['QUERY_STRING'].eql?('') ? '?' : '&') + Time.now.to_i.to_s | |
| res = ::Rack::Response.new('*', 302) | |
| res['Location'] = redir_url | |
| res.finish | |
| else | |
| ::Rack::Response.new('Service Unavailable', 503).finish | |
| end | |
| end | |
| end | |
| class MyApp | |
| def call(env) | |
| Rack::Response.new("Hello 2").finish | |
| end | |
| end | |
| deferred_dispatcher = DeferredDispatcher2.new( | |
| :require => "dummy.rb", | |
| :dispatch => 'MyApp') | |
| run deferred_dispatcher | |
| else | |
| run lambda { Rack::Response.new("Hello 1").finish } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment