Sha256: 9150327bd504a35476bf6aa5d58e63eaf67130daca8d26a11a1eb1cf13e561d6

Contents?: true

Size: 819 Bytes

Versions: 4

Compression:

Stored size: 819 Bytes

Contents

require 'pp'
module Xing
  module Static
    class GotoParam
      def initialize(app)
        @app = app
      end

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
xing-backend-0.0.23 lib/xing/static/goto_param.rb
xing-backend-0.0.22 lib/xing/static/goto_param.rb
xing-backend-0.0.21 lib/xing/static/goto_param.rb
xing-backend-0.0.20 lib/xing/static/goto_param.rb