diff --git a/README.markdown b/README.markdown index 5d5c073a6b..740656e71f 100644 --- a/README.markdown +++ b/README.markdown @@ -224,7 +224,7 @@ redirect "/new_url" use permanent redirect ``` ruby -redirect "/new_url", true +redirect "/new_url", :permanent => true ``` ## Raising Errors diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index d56cf6d0d9..38f63fd028 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -136,9 +136,11 @@ def error!(message, status=403) # Redirect to a new url. # # @param url [String] The url to be redirect. - # @param permanent [Boolean] Whether use permanent redirect with status code 304. - def redirect(url, permanent=false) - if permanent + # @param options [Hash] The options used when redirect. + # :permanent, default true. + def redirect(url, options = {}) + merged_options = {:permanent => false }.merge(options) + if merged_options[:permanent] status 304 else if env['HTTP_VERSION'] == 'HTTP/1.1' && request.request_method.to_s.upcase != "GET" diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index 32a3925e4d..79ff11671a 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -227,7 +227,7 @@ def app; subject end it "support permanent redirect" do subject.get('/hey') do - redirect "/ha", true + redirect "/ha", :permanent => true end get '/hey' last_response.status.should eq 304