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 --- src/gmutil.c | 8 ++++---- src/gmutil.h | 2 +- src/ui/documentwidget.c | 9 ++++++--- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') 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