Class: EsiForRack::Lookup::PassThrough

Inherits:
Object
  • Object
show all
Defined in:
lib/esi_for_rack/lookup.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PassThrough

Returns a new instance of PassThrough.



71
72
73
74
# File 'lib/esi_for_rack/lookup.rb', line 71

def initialize(app, env)
  @app = app
  @env = env
end

Instance Method Details

#[](path) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/esi_for_rack/lookup.rb', line 76

def [](path)
  return if path[0,4] == 'http'
  
  uri = URI(path)
  
  request = {
    "REQUEST_METHOD" => "GET",
    "SERVER_NAME" => @env['SERVER_NAME'],
    "SERVER_PORT" => @env['SERVER_PORT'],
    "QUERY_STRING" => uri.query.to_s,
    "PATH_INFO" => (!uri.path || uri.path.empty?) ? "/" : uri.path,
    "rack.url_scheme" => uri.scheme || @env['rack.url_scheme'] || 'http',
    "SCRIPT_NAME" => ""
  }

  response = @app.call(request)
  if response.first == 200
    EsiForRack.response_body_to_str(response.last)
  else
    nil
  end

rescue URI::InvalidURIError
  nil
end