Allow HTTP::Server::Context#redirect to take an URL (#659)

This commit is contained in:
Thomas Fini Hansen 2023-09-24 08:35:08 +02:00 committed by GitHub
parent a939a577de
commit cb9adcd188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,8 +17,8 @@ class HTTP::Server
@params ||= Kemal::ParamParser.new(@request, route_lookup.params) @params ||= Kemal::ParamParser.new(@request, route_lookup.params)
end end
def redirect(url : String, status_code : Int32 = 302, *, body : String? = nil, close : Bool = true) def redirect(url : String | URI, status_code : Int32 = 302, *, body : String? = nil, close : Bool = true)
@response.headers.add "Location", url @response.headers.add "Location", url.to_s
@response.status_code = status_code @response.status_code = status_code
@response.print(body) if body @response.print(body) if body
@response.close if close @response.close if close