Class: Conjur::Rack::PathPrefix

Inherits:
Object
  • Object
show all
Defined in:
lib/conjur/rack/path_prefix.rb

Constant Summary collapse

EMPTY_STRING =
""
SLASH =
"/"

Instance Method Summary collapse

Constructor Details

#initialize(app, path_prefix = nil) ⇒ PathPrefix

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PathPrefix.



9
10
11
12
# File 'lib/conjur/rack/path_prefix.rb', line 9

def initialize(app, path_prefix = nil)
  @app = app
  @path_prefix = /^#{Regexp.escape(path_prefix)}/
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
# File 'lib/conjur/rack/path_prefix.rb', line 15

def call(env)
  strip_path_prefix(env) 
  @app.call(env)
end

#strip_path_prefix(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
# File 'lib/conjur/rack/path_prefix.rb', line 21

def strip_path_prefix(env)
  ['PATH_INFO', 'REQUEST_URI'].each do |path_key|
    if env[path_key] =~ @path_prefix
      env[path_key].sub!(@path_prefix, EMPTY_STRING)
      env[path_key] = SLASH if env[path_key].empty?
    end
  end
end