From 432f87ca5238d1ff2ba619d513d423e707126c52 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 24 Aug 2024 09:13:55 -0400 Subject: [PATCH] Fix crash related to web server --- CHANGELOG.md | 1 + .../components/Web/WebServer/Http/HttpUtils.bs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8a36bcd..16aad9ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Rare crash related to NavBar +- Crash related to web server ## [0.25.3] - 2024-08-14 diff --git a/playlet-lib/src/components/Web/WebServer/Http/HttpUtils.bs b/playlet-lib/src/components/Web/WebServer/Http/HttpUtils.bs index 7c1748f2..f0bc2642 100644 --- a/playlet-lib/src/components/Web/WebServer/Http/HttpUtils.bs +++ b/playlet-lib/src/components/Web/WebServer/Http/HttpUtils.bs @@ -6,7 +6,14 @@ namespace Http function MimeType(uri = "" as string) as string map = m.MimeTypes if map = invalid - map = ParseJson(ReadAsciiFile("libpkg:/config/mime-types.json5")) + json = ReadAsciiFile("libpkg:/config/mime-types.json5") + if StringUtils.IsNullOrEmpty(json) + return "application/octet-stream" + end if + map = ParseJson(json) + if not IsAssociativeArray(map) + return "application/octet-stream" + end if m.MimeTypes = map end if ext = m.GetExtension(uri) @@ -29,7 +36,14 @@ namespace Http function HttpTitle(code = 0 as integer) as string map = m.httpCodesMap if map = invalid - map = ParseJson(ReadAsciiFile("libpkg:/config/http-codes.json5")) + json = ReadAsciiFile("libpkg:/config/http-codes.json5") + if StringUtils.IsNullOrEmpty(json) + return "" + end if + map = ParseJson(json) + if not IsAssociativeArray(map) + return "" + end if m.httpCodesMap = map end if return ValidString(map[`${code}`])