summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/farside/router.ex28
1 files changed, 13 insertions, 15 deletions
diff --git a/lib/farside/router.ex b/lib/farside/router.ex
index ce0eb0a..00d98e2 100644
--- a/lib/farside/router.ex
+++ b/lib/farside/router.ex
@@ -56,23 +56,21 @@ defmodule Farside.Router do
Enum.join(glob, "/")
end
- instance = cond do
+ cond do
conn.assigns[:throttle] != nil ->
- Farside.get_service(service_name)
- |> Farside.last_instance
- |> Farside.amend_instance(service_name, path)
+ send_resp(conn, :too_many_requests, "Too many requests - max request rate is 1 per second")
true ->
- Farside.get_service(service_name)
- |> Farside.pick_instance
- |> Farside.amend_instance(service_name, path)
- end
+ instance = Farside.get_service(service_name)
+ |> Farside.pick_instance
+ |> Farside.amend_instance(service_name, path)
- # Redirect to the available instance
- conn
- |> Plug.Conn.resp(:found, "")
- |> Plug.Conn.put_resp_header(
- "location",
- "#{instance}/#{path}#{get_query_params(conn)}"
- )
+ # Redirect to the available instance
+ conn
+ |> Plug.Conn.resp(:found, "")
+ |> Plug.Conn.put_resp_header(
+ "location",
+ "#{instance}/#{path}#{get_query_params(conn)}"
+ )
+ end
end
end