Guest User

Untitled

a guest
May 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. require 'appengine-rack'
  2. AppEngine::Rack.configure_app(
  3. :application => "gae151pre2test",
  4. :precompilation_enabled => true,
  5. :version => "1")
  6.  
  7. class HelloApp
  8. def call(env)
  9. ::Rack::Response.new("Hello").finish
  10. end
  11. end
  12.  
  13. case 1 # 1,2,3
  14. when 1
  15. s = File.lstat("/Users") ## <<<<<<<<<<<<<<<<<<<<<<
  16. p ["A: lstat=", s]
  17.  
  18. class DeferredDispatcher2
  19. def initialize args
  20. @args = args
  21. p ["DeferredDispatcher2#initialize: @args", @args]
  22. @args
  23. end
  24.  
  25. def call env
  26. p ["DeferredDispatcher2#call: @runtime", @runtime]
  27. p ["DeferredDispatcher2#call: @rack_app", @rack_app]
  28. if @runtime.nil?
  29. @runtime = true
  30. # 1: redirect with runtime and jruby-rack loaded
  31. redirect_or_error(env)
  32. elsif @rack_app.nil?
  33. p "[@rack_app.nil?==true]"
  34. s = nil
  35. begin
  36. s = File.lstat("/Users") ## <<<<<<<<<<<<<<<<<<<<<<
  37. rescue => e
  38. p "<<<<ERROR>>>> e=#{e.inspect}"
  39. raise e
  40. end
  41. p ["B: lstat=", s]
  42.  
  43. require @args[:require] if @args[:require]
  44. @rack_app = Object.module_eval(@args[:dispatch]).new
  45. # 2: redirect with framework required & dispatched
  46. redirect_or_error(env)
  47. else
  48. # 3: process all other requests
  49. @rack_app.call(env)
  50. end
  51. end
  52.  
  53. def redirect_or_error(env)
  54. if env['REQUEST_METHOD'].eql?('GET')
  55. redir_url = env['REQUEST_URI'] +
  56. (env['QUERY_STRING'].eql?('') ? '?' : '&') + Time.now.to_i.to_s
  57. res = ::Rack::Response.new('*', 302)
  58. res['Location'] = redir_url
  59. res.finish
  60. else
  61. ::Rack::Response.new('Service Unavailable', 503).finish
  62. end
  63. end
  64. end
  65. deferred_dispatcher = DeferredDispatcher2.new(
  66. :require => nil,
  67. :dispatch => 'HelloApp')
  68. run deferred_dispatcher
  69. when 2
  70. deferred_dispatcher = AppEngine::Rack::DeferredDispatcher.new(
  71. :require => "time", # dummy!!
  72. :dispatch => 'HelloApp')
  73. run deferred_dispatcher
  74. when 3
  75. run HelloApp.new
  76. #lambda { ::Rack::Response.new("Hello").finish }
  77. end
Add Comment
Please, Sign In to add comment