Class: Xing::Static::GotoParam

Inherits:
Object
  • Object
show all
Defined in:
lib/xing/static/goto_param.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ GotoParam

Returns a new instance of GotoParam.



5
6
7
# File 'lib/xing/static/goto_param.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/xing/static/goto_param.rb', line 9

def call(env)
  status, headers, body = @app.call(env)
  default = [ status, headers, body ]
  request_path = env["SCRIPT_NAME"] + env["PATH_INFO"]
  if env["QUERY_STRING"]
    request_path += "&#{env["QUERY_STRING"]}"
  end

  redirect = [ 301, headers.merge("Location" => "/?goto=#{request_path}", "Content-Length" => "0"), [] ]

  return default unless status == 404
  return default if /\A(assets|fonts|system)/ =~ request_path
  return default if /\.(xml|html|ico|txt)\z/ =~ request_path
  return default if /goto=/ =~ env["QUERY_STRING"]

  return redirect
rescue => ex
  pp ex
end