Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. module Merb
  2. module Rack
  3. class PathPrefix < Merb::Rack::Middleware
  4.  
  5. def initialize(app, path_prefix = nil)
  6. super(app)
  7. @path_prefix = /^#{Regexp.escape(path_prefix)}/
  8. end
  9.  
  10. def deferred?(env)
  11. strip_path_prefix(env)
  12. @app.deferred?(env)
  13. end
  14.  
  15. def call(env)
  16. strip_path_prefix(env)
  17. @app.call(env)
  18. end
  19.  
  20. def strip_path_prefix(env)
  21. ['PATH_INFO', 'REQUEST_URI'].each do |path_key|
  22. if env[path_key] =~ @path_prefix
  23. env[path_key].sub!(@path_prefix, '')
  24. env[path_key] = '/' if env[path_key].empty?
  25. end
  26. end
  27. end
  28.  
  29. end
  30. end
  31. end
Add Comment
Please, Sign In to add comment