From 97f1d26cbcc4ef9ce11739d8f0e9d092de5a6262 Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Mon, 15 Nov 2021 17:15:36 -0700 Subject: [PATCH] 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. --- lib/farside/router.ex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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