Skip to content

Commit

Permalink
Merge branch 'whaileee/inets/httpd/connect_addr/ERIERL-1152/OTP-19377…
Browse files Browse the repository at this point in the history
…' into maint

* whaileee/inets/httpd/connect_addr/ERIERL-1152/OTP-19377:
  add connect_addr to Env in mod_esi callback
  • Loading branch information
Whaileee committed Dec 2, 2024
2 parents ff3d6dd + 4e8adc4 commit 7a4283b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/inets/src/http_server/httpd_script_env.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ which_method(#mod{method = Method}) ->
which_request_uri(#mod{request_uri = RUri}) ->
RUri.

which_connect_addr(#mod{socket = Socket, socket_type = SocketType}) when
SocketType == ip_comm;
element(1, SocketType) == ip_comm ->
maybe
{ok, {Addr, _Port}} ?= inet:sockname(Socket),
inet:ntoa(Addr)
end;
which_connect_addr(#mod{socket = Socket, socket_type = SocketType}) when
SocketType == ssl;
element(1, SocketType) == ssl ->
maybe
{ok, {Addr, _Port}} ?= ssl:sockname(Socket),
inet:ntoa(Addr)
end.

create_basic_elements(esi, ModData) ->
[{server_software, which_server(ModData)},
{server_name, which_name(ModData)},
Expand All @@ -96,6 +111,7 @@ create_basic_elements(esi, ModData) ->
{server_port, which_port(ModData)},
{request_method, which_method(ModData)},
{remote_addr, which_peername(ModData)},
{connect_addr, which_connect_addr(ModData)},
{peer_cert, which_peercert(ModData)},
{script_name, which_request_uri(ModData)}];

Expand All @@ -108,6 +124,7 @@ create_basic_elements(cgi, ModData) ->
{"SERVER_PORT", integer_to_list(which_port(ModData))},
{"REQUEST_METHOD", which_method(ModData)},
{"REMOTE_ADDR", which_peername(ModData)},
{"CONNECT_ADDR", which_connect_addr(ModData)},
{"SCRIPT_NAME", which_request_uri(ModData)}].

create_http_header_elements(ScriptType, Headers) ->
Expand Down

0 comments on commit 7a4283b

Please sign in to comment.