Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'appengine-rack'
- AppEngine::Rack.configure_app(
- :application => "gae151pre2test",
- :precompilation_enabled => true,
- :version => "1")
- class HelloApp
- def call(env)
- ::Rack::Response.new("Hello").finish
- end
- end
- case 1 # 1,2,3
- when 1
- s = File.lstat("/Users") ## <<<<<<<<<<<<<<<<<<<<<<
- p ["A: lstat=", s]
- class DeferredDispatcher2
- def initialize args
- @args = args
- p ["DeferredDispatcher2#initialize: @args", @args]
- @args
- end
- def call env
- p ["DeferredDispatcher2#call: @runtime", @runtime]
- p ["DeferredDispatcher2#call: @rack_app", @rack_app]
- if @runtime.nil?
- @runtime = true
- # 1: redirect with runtime and jruby-rack loaded
- redirect_or_error(env)
- elsif @rack_app.nil?
- p "[@rack_app.nil?==true]"
- s = nil
- begin
- s = File.lstat("/Users") ## <<<<<<<<<<<<<<<<<<<<<<
- rescue => e
- p "<<<<ERROR>>>> e=#{e.inspect}"
- raise e
- end
- p ["B: lstat=", s]
- require @args[:require] if @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
- deferred_dispatcher = DeferredDispatcher2.new(
- :require => nil,
- :dispatch => 'HelloApp')
- run deferred_dispatcher
- when 2
- deferred_dispatcher = AppEngine::Rack::DeferredDispatcher.new(
- :require => "time", # dummy!!
- :dispatch => 'HelloApp')
- run deferred_dispatcher
- when 3
- run HelloApp.new
- #lambda { ::Rack::Response.new("Hello").finish }
- end
Add Comment
Please, Sign In to add comment