Skip to content

Commit b70a518

Browse files
Merge pull request #391 from smetana/master
fix request url port in payloads for HTTPS requests
2 parents 8701e9d + 4ac430b commit b70a518

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/sentry/plug.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ if Code.ensure_loaded?(Plug) do
230230
|> Plug.Conn.fetch_query_params()
231231

232232
%{
233-
url: "#{conn.scheme}://#{conn.host}:#{conn.port}#{conn.request_path}",
233+
url: Plug.Conn.request_url(conn),
234234
method: conn.method,
235235
data: handle_data(conn, body_scrubber),
236236
query_string: conn.query_string,

test/plug_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,26 @@ defmodule Sentry.PlugTest do
198198
assert body =~ ~s{"title":"abc-123"}
199199
end
200200

201+
test "request url" do
202+
# Default ports
203+
conn = conn(:get, "http://www.example.com:80/error_route")
204+
%{url: url} = Sentry.Plug.build_request_interface_data(conn, [])
205+
assert url == "http://www.example.com/error_route"
206+
207+
conn = conn(:get, "https://www.example.com:443/error_route")
208+
%{url: url} = Sentry.Plug.build_request_interface_data(conn, [])
209+
assert url == "https://www.example.com/error_route"
210+
211+
# Custom ports
212+
conn = conn(:get, "http://www.example.com:1234/error_route")
213+
%{url: url} = Sentry.Plug.build_request_interface_data(conn, [])
214+
assert url == "http://www.example.com:1234/error_route"
215+
216+
conn = conn(:get, "https://www.example.com:1234/error_route")
217+
%{url: url} = Sentry.Plug.build_request_interface_data(conn, [])
218+
assert url == "https://www.example.com:1234/error_route"
219+
end
220+
201221
defp update_req_cookie(conn, name, value) do
202222
req_headers =
203223
conn.req_headers

0 commit comments

Comments
 (0)