Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/reverse_proxy_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ defmodule ReverseProxyPlug do
end

defp prepare_url(conn, overrides) do
keys = [:scheme, :host, :port, :query_string]
keys = [:scheme, :host, :port, :query_string, :path_params]

x =
conn
Expand All @@ -249,6 +249,7 @@ defmodule ReverseProxyPlug do

request_path = Enum.join(conn.path_info, "/")
request_path = Path.join(overrides[:request_path] || "/", request_path)
request_path = replace_path_variables(request_path, x[:path_params])

request_path =
if String.ends_with?(conn.request_path, "/") && !String.ends_with?(request_path, "/"),
Expand Down Expand Up @@ -456,4 +457,10 @@ defmodule ReverseProxyPlug do
Conn.put_resp_header(conn, header, value)
end)
end

defp replace_path_variables(path, path_params) do
Regex.replace(~r/:([a-zA-Z_]+)/, path, fn match, var_name ->
Map.get(path_params, var_name, match)
end)
end
end