diff options
| author | Ben Busby <noreply+git@benbusby.com> | 2021-11-15 17:15:36 -0700 |
|---|---|---|
| committer | Ben Busby <noreply+git@benbusby.com> | 2021-11-15 17:15:36 -0700 |
| commit | 97f1d26cbcc4ef9ce11739d8f0e9d092de5a6262 (patch) | |
| tree | 52742f2f713d4e21b38a4198cc6b64cee22f0cc6 /lib | |
| parent | 8ce5b04f510333b5e8552d30e84276e08c29ecb2 (diff) | |
| download | farside-97f1d26cbcc4ef9ce11739d8f0e9d092de5a6262.tar.gz | |
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.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/farside/router.ex | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/farside/router.ex b/lib/farside/router.ex index e2014b2..e74f29e 100644 --- a/lib/farside/router.ex +++ b/lib/farside/router.ex @@ -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 |
