From 9a4032bbba8846d1f5c92b4c39743dc6884f06ec Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 4 Dec 2020 21:16:19 +0200 Subject: Windows: Dealing with "file:///" URIs --- src/gmrequest.c | 9 +++++++++ src/gmutil.c | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gmrequest.c b/src/gmrequest.c index a1284078..2402cc40 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c @@ -526,6 +526,12 @@ void submit_GmRequest(iGmRequest *d) { } else if (equalCase_Rangecc(url.scheme, "file")) { iString *path = collect_String(urlDecode_String(collect_String(newRange_String(url.path)))); +#if defined (iPlatformMsys) + /* Remove the extra slash from the beginning. */ + if (startsWith_String(path, "/")) { + remove_Block(&path->chars, 0, 1); + } +#endif iFile * f = new_File(path); if (open_File(f, readOnly_FileMode)) { /* TODO: Check supported file types: images, audio */ @@ -555,6 +561,9 @@ void submit_GmRequest(iGmRequest *d) { else if (endsWithCase_String(path, ".mp3")) { setCStr_String(&resp->meta, "audio/mpeg"); } + else if (endsWithCase_String(path, ".mid")) { + setCStr_String(&resp->meta, "audio/midi"); + } else { setCStr_String(&resp->meta, "application/octet-stream"); } diff --git a/src/gmutil.c b/src/gmutil.c index 557a82f8..94f00ce1 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -192,7 +192,10 @@ const iString *absoluteUrl_String(const iString *d, const iString *urlMaybeRelat iString *makeFileUrl_String(const iString *localFilePath) { iString *url = cleaned_Path(localFilePath); replace_Block(&url->chars, '\\', '/'); /* in case it's a Windows path */ - set_String(url, collect_String(urlEncodeExclude_String(url, "/"))); + set_String(url, collect_String(urlEncodeExclude_String(url, "/:"))); +#if defined (iPlatformMsys) + prependChar_String(url, '/'); /* three slashes */ +#endif prependCStr_String(url, "file://"); return url; } -- cgit v1.2.3