mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Use 302 to redirect instead of 301
`301` means "Moved Permanently", so browser caches this redirect, it is used when changing server URL. `302` means "Found", it is used generally (e.g. redirect top page after login). Each of `301`, `302`, `303` and `307` means redict, but they are different. We could choice those status in case.
This commit is contained in:
parent
9aa0819f29
commit
55361b3c9a
2 changed files with 3 additions and 3 deletions
|
@ -204,7 +204,7 @@ describe "Kemal::RouteHandler" do
|
||||||
request = HTTP::Request.new("GET", "/")
|
request = HTTP::Request.new("GET", "/")
|
||||||
io_with_context = create_request_and_return_io(kemal, request)
|
io_with_context = create_request_and_return_io(kemal, request)
|
||||||
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
client_response.status_code.should eq(301)
|
client_response.status_code.should eq(302)
|
||||||
client_response.headers.has_key?("Location").should eq(true)
|
client_response.headers.has_key?("Location").should eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,9 +8,9 @@ class HTTP::Server
|
||||||
Kemal::ParamParser.new(@route, @request).parse
|
Kemal::ParamParser.new(@route, @request).parse
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect(url)
|
def redirect(url, status_code = 302)
|
||||||
@response.headers.add "Location", url
|
@response.headers.add "Location", url
|
||||||
@response.status_code = 301
|
@response.status_code = status_code
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue