Include query params in service instance redirect

Query params ("/watch?v=dQw4w9WgXcQ" for instance) would previously be
lost in Farside redirects. This now includes them if they were included
in the original request.
This commit is contained in:
Ben Busby 2021-11-15 17:15:36 -07:00
parent 8ce5b04f51
commit 97f1d26cbc
No known key found for this signature in database
GPG key ID: 339B7B7EB5333D14

View file

@ -28,12 +28,21 @@ defmodule Farside.Router do
path = Enum.join(glob, "/")
instance = Farside.pick_instance(service)
params =
cond do
String.length(conn.query_string) > 0 ->
"?#{conn.query_string}"
true ->
""
end
# Redirect to the available instance
conn
|> Plug.Conn.resp(:found, "")
|> Plug.Conn.put_resp_header(
"location",
"#{instance}/#{path}"
"#{instance}/#{path}#{params}"
)
end
end