Skip to content

Commit 2ad330c

Browse files
committed
Release v0.1.3
1 parent 0c73bc7 commit 2ad330c

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

gleam.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "minigui"
2-
version = "0.1.2"
2+
version = "0.1.3"
33
description = "Basic GUI library for Gleam (Win32/GTK) using a C port with precompiled binaries."
44
licences = ["MIT"]
55
repository = { type = "github", user = "Aztekode", repo = "minigui" }

src/minigui_bootstrap.erl

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,45 @@ ssl_http_opts(Url) ->
153153
end;
154154
V -> V
155155
end,
156-
SslOpts0 = [{verify, verify_peer}],
156+
Host = url_host(Url),
157+
Base0 = httpc:ssl_verify_host_options(true),
158+
Base =
159+
case Host of
160+
"" -> Base0;
161+
_ -> lists:keystore(server_name_indication, 1, Base0, {server_name_indication, Host})
162+
end,
157163
SslOpts =
158164
case Ca of
159-
"" -> SslOpts0;
160-
_ -> [{cacertfile, Ca} | SslOpts0]
165+
"" ->
166+
Base;
167+
_ ->
168+
%% Replace any existing cacerts entry with cacertfile if provided.
169+
[{cacertfile, Ca} | lists:keydelete(cacerts, 1, Base)]
161170
end,
162171
[{ssl, SslOpts}]
163172
end.
164173

165174
is_http_url(Url) when is_list(Url) ->
166175
lists:prefix("http://", Url).
167176

177+
url_host(Url) when is_list(Url) ->
178+
try
179+
Parts = uri_string:parse(Url),
180+
Host0 = maps:get(host, Parts, ""),
181+
normalize_host(Host0)
182+
catch
183+
_:_ -> ""
184+
end.
185+
186+
normalize_host(undefined) ->
187+
"";
188+
normalize_host(Host) when is_binary(Host) ->
189+
binary_to_list(Host);
190+
normalize_host(Host) when is_list(Host) ->
191+
Host;
192+
normalize_host(_) ->
193+
"".
194+
168195
maybe_chmod(Path) ->
169196
case os:type() of
170197
{win32, _} -> ok;
@@ -284,9 +311,12 @@ ensure_cached(Url, CachePath) ->
284311
download_with_retries(Url, CachePath, 3)
285312
end.
286313

287-
download_with_retries(_Url, _Path, 0) ->
288-
{error, retries_exhausted};
289314
download_with_retries(Url, Path, N) ->
315+
download_with_retries(Url, Path, N, undefined).
316+
317+
download_with_retries(_Url, _Path, 0, LastReason) ->
318+
{error, {retries_exhausted, LastReason}};
319+
download_with_retries(Url, Path, N, _LastReason) ->
290320
Tmp = Path ++ ".tmp",
291321
case download_to_file(Url, Tmp) of
292322
ok ->
@@ -298,10 +328,10 @@ download_with_retries(Url, Path, N) ->
298328
_ = file:delete(Tmp),
299329
{error, Reason}
300330
end;
301-
{error, _Reason} ->
331+
{error, Reason} ->
302332
_ = file:delete(Tmp),
303333
timer:sleep(300),
304-
download_with_retries(Url, Path, N - 1)
334+
download_with_retries(Url, Path, N - 1, Reason)
305335
end.
306336

307337
maybe_verify_sha256(Url, Path) ->

0 commit comments

Comments
 (0)