summaryrefslogtreecommitdiff
path: root/src/gmrequest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gmrequest.c')
-rw-r--r--src/gmrequest.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c
index 1a7c37df..3dd92eec 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -597,16 +597,18 @@ void submit_GmRequest(iGmRequest *d) {
597 else if (equalCase_Rangecc(url.scheme, "file")) { 597 else if (equalCase_Rangecc(url.scheme, "file")) {
598 /* TODO: Move handling of "file://" URLs elsewhere, it's getting complex. */ 598 /* TODO: Move handling of "file://" URLs elsewhere, it's getting complex. */
599 iString *path = collect_String(localFilePathFromUrl_String(&d->url)); 599 iString *path = collect_String(localFilePathFromUrl_String(&d->url));
600 /* Note: As a local file path, `path` uses the OS directory separators
601 (i.e., \ on Windows). `Archive` accepts both. */
600 iFile *f = new_File(path); 602 iFile *f = new_File(path);
601 if (isDirectory_(path)) { 603 if (isDirectory_(path)) {
602 if (endsWith_String(path, "/")) { 604 if (endsWith_String(path, iPathSeparator)) {
603 removeEnd_String(path, 1); 605 removeEnd_String(path, 1);
604 } 606 }
605 resp->statusCode = success_GmStatusCode; 607 resp->statusCode = success_GmStatusCode;
606 setCStr_String(&resp->meta, "text/gemini"); 608 setCStr_String(&resp->meta, "text/gemini");
607 iString *page = collectNew_String(); 609 iString *page = collectNew_String();
608 iString *parentDir = collectNewRange_String(dirName_Path(path)); 610 iString *parentDir = collectNewRange_String(dirName_Path(path));
609 appendFormat_String(page, "=> %s " upArrow_Icon " %s/\n\n", 611 appendFormat_String(page, "=> %s " upArrow_Icon " %s" iPathSeparator "\n\n",
610 cstrCollect_String(makeFileUrl_String(parentDir)), 612 cstrCollect_String(makeFileUrl_String(parentDir)),
611 cstr_String(parentDir)); 613 cstr_String(parentDir));
612 appendFormat_String(page, "# %s\n", cstr_Rangecc(baseName_Path(path))); 614 appendFormat_String(page, "# %s\n", cstr_Rangecc(baseName_Path(path)));
@@ -630,7 +632,7 @@ void submit_GmRequest(iGmRequest *d) {
630 appendFormat_String(page, "=> %s %s%s\n", 632 appendFormat_String(page, "=> %s %s%s\n",
631 cstrCollect_String(makeFileUrl_String(path_FileInfo(entry))), 633 cstrCollect_String(makeFileUrl_String(path_FileInfo(entry))),
632 cstr_Rangecc(baseName_Path(path_FileInfo(entry))), 634 cstr_Rangecc(baseName_Path(path_FileInfo(entry))),
633 isDirectory_FileInfo(entry) ? "/" : ""); 635 isDirectory_FileInfo(entry) ? iPathSeparator : "");
634 iRelease(entry); 636 iRelease(entry);
635 } 637 }
636 set_Block(&resp->body, utf8_String(page)); 638 set_Block(&resp->body, utf8_String(page));
@@ -652,7 +654,8 @@ void submit_GmRequest(iGmRequest *d) {
652 iString *entryPath = collect_String(copy_String(path)); 654 iString *entryPath = collect_String(copy_String(path));
653 remove_Block(&entryPath->chars, 0, size_String(container) + 1); /* last slash, too */ 655 remove_Block(&entryPath->chars, 0, size_String(container) + 1); /* last slash, too */
654 iBool isDir = isDirectory_Archive(arch, entryPath); 656 iBool isDir = isDirectory_Archive(arch, entryPath);
655 if (isDir && !isEmpty_String(entryPath) && !endsWith_String(entryPath, "/")) { 657 if (isDir && !isEmpty_String(entryPath) &&
658 !endsWith_String(entryPath, iPathSeparator)) {
656 /* Must have a slash for directories, otherwise relative navigation 659 /* Must have a slash for directories, otherwise relative navigation
657 will not work. */ 660 will not work. */
658 resp->statusCode = redirectPermanent_GmStatusCode; 661 resp->statusCode = redirectPermanent_GmStatusCode;
@@ -683,7 +686,9 @@ void submit_GmRequest(iGmRequest *d) {
683 const iRangecc parentDir = dirName_Path(collectNewRange_String(curDir)); 686 const iRangecc parentDir = dirName_Path(collectNewRange_String(curDir));
684 if (!equal_Rangecc(parentDir, ".")) { 687 if (!equal_Rangecc(parentDir, ".")) {
685 /* A subdirectory. */ 688 /* A subdirectory. */
686 appendFormat_String(page, "=> ../ " upArrow_Icon " %s/\n", 689 appendFormat_String(page,
690 "=> ../ " upArrow_Icon " %s" iPathSeparator
691 "\n",
687 cstr_Rangecc(parentDir)); 692 cstr_Rangecc(parentDir));
688 } 693 }
689 else { 694 else {