Skip to content

Commit

Permalink
mod_spam_filter: add timeout to http request
Browse files Browse the repository at this point in the history
  • Loading branch information
sstrigler committed Jan 8, 2025
1 parent 9bae343 commit c752dbf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mod_spam_filter/src/mod_spam_filter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
-include_lib("xmpp/include/xmpp.hrl").

-define(COMMAND_TIMEOUT, timer:seconds(30)).
-define(HTTPC_TIMEOUT, timer:seconds(5)).

-type url() :: binary().
-type filename() :: binary() | none.
Expand Down Expand Up @@ -421,7 +422,10 @@ extract_urls(Body) ->
-spec resolve_redirects([url()], [url()]) -> [url()].
resolve_redirects([], Result) -> Result;
resolve_redirects([Url | Rest], Acc) ->
case httpc:request(get, {Url, [{"user-agent", "curl/8.7.1"}]}, [{autoredirect, false}], []) of
case
httpc:request(get, {Url, [{"user-agent", "curl/8.7.1"}]},
[{autoredirect, false}, {timeout, ?HTTPC_TIMEOUT}], [])
of
{ok, {{_, Moved, _}, Headers, _Body}} when Moved >= 300, Moved < 400 ->
Location = proplists:get_value("location", Headers),
case lists:member(Location, Acc) of
Expand Down

0 comments on commit c752dbf

Please sign in to comment.