Skip to content

Commit

Permalink
Allow to specify a port from the conn
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanic committed Nov 15, 2023
1 parent 53f304f commit fc9fbdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/plug/adapters/test/conn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ defmodule Plug.Adapters.Test.Conn do
})
}

conn_port = if conn.port != 0, do: conn.port, else: 80

%Plug.Conn{
conn
| adapter: {__MODULE__, state},
host: uri.host || conn.host || "www.example.com",
method: method,
owner: owner,
path_info: split_path(uri.path),
port: uri.port || 80,
port: uri.port || conn_port,
remote_ip: conn.remote_ip || {127, 0, 0, 1},
req_headers: req_headers,
request_path: uri.path,
Expand Down
6 changes: 6 additions & 0 deletions test/plug/adapters/test/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ defmodule Plug.Adapters.Test.ConnTest do
assert child_conn.remote_ip == {151, 236, 219, 228}
end

test "use existing conn.port if exists" do
conn_with_port = %Plug.Conn{conn(:get, "/") | port: 4200}
child_conn = Plug.Adapters.Test.Conn.conn(conn_with_port, :get, "/", foo: "bar")
assert child_conn.port == 4200
end

test "use custom peer data" do
peer_data = %{address: {127, 0, 0, 1}, port: 111_317}
conn = conn(:get, "/") |> put_peer_data(peer_data)
Expand Down

0 comments on commit fc9fbdd

Please sign in to comment.