lib/roda.rb in roda-cj-0.9.4 vs lib/roda.rb in roda-cj-0.9.5

- old
+ new

@@ -427,11 +427,11 @@ def response scope.response end # Immediately redirect to the given path. - def redirect(path, status=302) + def redirect(path=default_redirect_path, status=302) response.redirect(path, status) throw :halt, response.finish end # If this is a GET request for the root ("/"), yield to the match block. @@ -531,9 +531,22 @@ # Don't mutate SCRIPT_NAME, breaks try env[SCRIPT_NAME] += vars.shift env[PATH_INFO] = matchdata.post_match captures.concat(vars) + end + + # The default path to use for redirects when a path is not given. + # For non-GET requests, redirects to the current path, which will + # trigger a GET request. This is to make the common case where + # a POST request will redirect to a GET request at the same location + # will work fine. + # + # If the current request is a GET request, raise an error, as otherwise + # it is easy to create an infinite redirect. + def default_redirect_path + raise RodaError, "must provide path argument to redirect for get requests" if is_get? + full_path_info end # If all of the arguments match, yields to the match block and # returns the rack response when the block returns. If any of # the match arguments doesn't match, does nothing.