0
0
Fork 0

Add redirect to response

Now a relocation can be done, by calling redirect with the URL you want
relocate to.
This will set the Location header and set the status code to 302.
This commit is contained in:
Stormwind 2012-11-30 18:58:32 +01:00
parent d28dc720d1
commit facd4f143b
2 changed files with 19 additions and 0 deletions

View File

@ -67,5 +67,14 @@ module Zero
self.header['Content-Type'] = value
end
# Sets the Location header to the given URL and the status code to 302.
#
# @param [String] location Redirect URL
#
def redirect(location)
self.status = 302
self.header['Location'] = location
end
end
end

View File

@ -125,4 +125,14 @@ describe Zero::Response do
end
end
describe '#redirect' do
it "sets the status to 302 and the given Location URL in header" do
subject.redirect 'http://foo.bar/relocated/thingy'
value = subject.to_a
value[0].should eq(302)
value[1]['Location'].should eq('http://foo.bar/relocated/thingy')
end
end
end