From a3af3912421d5848bce9eac7031da406bac2ba5b Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 6 Nov 2020 21:59:39 +0200 Subject: Automatic redirects to the same scheme IssueID #16 --- res/about/version.gmi | 1 + src/gmutil.c | 8 ++++---- src/gmutil.h | 2 +- src/ui/documentwidget.c | 9 ++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/res/about/version.gmi b/res/about/version.gmi index 0192eaaa..12c00b3b 100644 --- a/res/about/version.gmi +++ b/res/about/version.gmi @@ -13,6 +13,7 @@ * Added a context menu item for opening HTTP links in the default browser even when a proxy is configured. * ${CTRL+}Click opens tab in background, ${SHIFT+}${CTRL+}Click opens as foreground tab. The same modifier keys work with keyboard navigation. * Improved word wrapping of emoticons (:D). +* Automatic redirects allowed when the destination URL uses the same scheme as the originating URL. For example, when using a proxy, HTTP(S) is allowed to automatically redirect to other HTTP(S) URLs. * Windows: Fixed handling of drag-and-dropped and command line file paths. ## 0.7.2 diff --git a/src/gmutil.c b/src/gmutil.c index 52fe6b28..6166efd6 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -247,11 +247,11 @@ static const struct { "Invalid Redirect", "The server responded with a redirect but did not provide a valid destination URL. " "Perhaps the server is malfunctioning." } }, - { nonGeminiRedirect_GmStatusCode, + { schemeChangeRedirect_GmStatusCode, { 0x27a0, /* dashed arrow */ - "Redirect to Non-Gemini URL", - "The server attempted to redirect us to a non-Gemini URL. Here is the link so you " - "can open it manually if appropriate."} }, + "Scheme-Changing Redirect", + "The server attempted to redirect us to a URL whose scheme is different than the " + "originating URL's scheme. Here is the link so you can open it manually if appropriate."} }, { tooManyRedirects_GmStatusCode, { 0x27a0, /* dashed arrow */ "Too Many Redirects", diff --git a/src/gmutil.h b/src/gmutil.h index 97c2d675..6778465a 100644 --- a/src/gmutil.h +++ b/src/gmutil.h @@ -33,7 +33,7 @@ enum iGmStatusCode { /* clientside status codes */ clientSide_GmStatusCode = -100, invalidRedirect_GmStatusCode, - nonGeminiRedirect_GmStatusCode, + schemeChangeRedirect_GmStatusCode, tooManyRedirects_GmStatusCode, invalidHeader_GmStatusCode, unsupportedMimeType_GmStatusCode, diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index f1506fc3..1b6e485a 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -694,7 +694,7 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode iBool useBanner = iTrue; if (meta) { switch (code) { - case nonGeminiRedirect_GmStatusCode: + case schemeChangeRedirect_GmStatusCode: case tooManyRedirects_GmStatusCode: appendFormat_String(src, "\n=> %s\n", cstr_String(meta)); break; @@ -1031,12 +1031,15 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) { if (d->redirectCount >= 5) { showErrorPage_DocumentWidget_(d, tooManyRedirects_GmStatusCode, dstUrl); } - else if (equalCase_Rangecc(urlScheme_String(dstUrl), "gemini")) { + else if (equalCase_Rangecc(urlScheme_String(dstUrl), + cstr_Rangecc(urlScheme_String(d->mod.url)))) { + /* Redirects with the same scheme are automatic. */ postCommandf_App( "open redirect:%d url:%s", d->redirectCount + 1, cstr_String(dstUrl)); } else { - showErrorPage_DocumentWidget_(d, nonGeminiRedirect_GmStatusCode, dstUrl); + /* Scheme changes must be manually approved. */ + showErrorPage_DocumentWidget_(d, schemeChangeRedirect_GmStatusCode, dstUrl); } iReleasePtr(&d->request); } -- cgit v1.2.3