lib/rack-slashenforce.rb in rack-slashenforce-0.0.2 vs lib/rack-slashenforce.rb in rack-slashenforce-0.0.3

- old
+ new

@@ -1,10 +1,10 @@ module Rack module SlashEnforce def self.version - '0.0.2' + '0.0.3' end end class RemoveTrailingSlashes # regexp to match strings that start and end with a slash @@ -13,11 +13,11 @@ def initialize(app) @app = app end def call(env) - if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH + if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH && env['REQUEST_METHOD'] == 'GET' env['PATH_INFO'].sub!(/(\/)+$/,'') [301, {"Location" => Rack::Request.new(env).url, "Content-Type" => ""}, []] else @app.call(env) end @@ -31,10 +31,10 @@ def initialize(app) @app = app end def call(env) - if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH + if env['PATH_INFO'] != '/' && env['PATH_INFO'] =~ MATCH && env['REQUEST_METHOD'] == 'GET' env['PATH_INFO'] += '/' [301, {"Location" => Rack::Request.new(env).url, "Content-Type" => ""}, []] else @app.call(env) end \ No newline at end of file