Sha256: cf9a62c1511ca409d4a85a73f7f939dc9c4229ccae750adef061f288dbbfcfce
Contents?: true
Size: 947 Bytes
Versions: 1
Compression:
Stored size: 947 Bytes
Contents
module Rack module SlashEnforce def self.version '0.0.1' end end class RemoveSlash # regexp to match strings that start and end with a slash MATCH = %r{^/(.*)/$} def initialize(app) @app = app end def call(env) if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH env['PATH_INFO'].sub!(/(\/)+$/,'') [301, {"Location" => Rack::Request.new(env).url, "Content-Type" => ""}, []] else @app.call(env) end end end class AppendSlash # regexp to match strings without periods that start and end with a slash MATCH = %r{^/([^.]*)[^/]$} def initialize(app) @app = app end def call(env) if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH env['PATH_INFO'] += '/' [301, {"Location" => Rack::Request.new(env).url, "Content-Type" => ""}, []] else @app.call(env) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-slashenforce-0.0.1 | lib/rack-slashenforce.rb |