Class Rack::Recursive
In: lib/rack/recursive.rb
Parent: Object

Rack::Recursive allows applications called down the chain to include data from other applications (by using rack[…] or raise a ForwardRequest to redirect internally.

Methods

call   include   new  

Public Class methods

[Source]

    # File lib/rack/recursive.rb, line 33
33:     def initialize(app)
34:       @app = app
35:     end

Public Instance methods

[Source]

    # File lib/rack/recursive.rb, line 37
37:     def call(env)
38:       @script_name = env["SCRIPT_NAME"]
39:       @app.call(env.merge('rack.recursive.include' => method(:include)))
40:     rescue ForwardRequest => req
41:       call(env.merge(req.env))
42:     end

[Source]

    # File lib/rack/recursive.rb, line 44
44:     def include(env, path)
45:       unless path.index(@script_name) == 0 && (path[@script_name.size] == ?/ ||
46:                                                path[@script_name.size].nil?)
47:         raise ArgumentError, "can only include below #{@script_name}, not #{path}"
48:       end
49: 
50:       env = env.merge("PATH_INFO" => path, "SCRIPT_NAME" => @script_name,
51:                       "REQUEST_METHOD" => "GET",
52:                       "CONTENT_LENGTH" => "0", "CONTENT_TYPE" => "",
53:                       "rack.input" => StringIO.new(""))
54:       @app.call(env)
55:     end

[Validate]