Top Level Namespace

Defined Under Namespace

Modules: ActionDispatch

Instance Method Summary collapse

Instance Method Details

#_proxy_request(env, path, args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/proxy_request.rb', line 5

def _proxy_request(env,path,args)


  args = {
    :csrf => true 
  }.merge(args)

  req = ActionDispatch::Request.new(env)

  if args[:csrf] and env['rack.session']['_csrf_token'] != req.headers["X-CSRF-Token"]
    return [
      403,
      {'Content-Type' => 'text/html', 'Content-Length' => '3'},
      ['403']
    ]
  end

  path_params = path.to_s % Hash[req.params.map{|a| [a.first.to_sym, a.last]}]

  if path_params.starts_with?("http:/")
    path_params.gsub!('http:/','http://')
  end

  if req.params['format']
    path_params += "." + req.params['format']
  end

  uri = URI.parse( path_params )

  http_req = HTTPClient.new

  elapsed_time = Benchmark.ms do
    @response = http_req.request(req.method,uri.to_s)
  end

  [
    @response.status,
    {
      'Content-Type' => @response.header.contenttype,
      'X-Proxy-Runtime' => (elapsed_time/1000.0).to_s
    },
    [@response.body.content]
  ]

end