Sha256: 9fb674fed8b3d6ebc21888bc5fb4094fcb2f4f9d9907ba9dad068033036d46b3

Contents?: true

Size: 637 Bytes

Versions: 1

Compression:

Stored size: 637 Bytes

Contents

module Rack
  module SeoRedirect
    class TrailingSlash < Base
      def initialize app, slash = false
        super(app)
        @should_ends_with_slash = slash
      end

      def call env
        @env = env
        req = Rack::Request.new(env)
        ends_with_slash = !!(req.path =~ /\A(.*)\/\z/)

        if req.get? && req.path != '/' && @should_ends_with_slash != ends_with_slash
          path = @should_ends_with_slash ? "#{req.path}/" : "#{$1}"
          url = build_url(:path => path)

          [ 301, headers(url), [ redirect_message(url) ] ]
        else
          @app.call(env)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-seo_redirect-0.0.1 lib/rack/seo_redirect/trailing_slash.rb