Auto redirect if the new URL just adds a trailing slash (#271)

This commit is contained in:
mooff 2021-12-03 14:59:34 +00:00 committed by GitHub
parent 6e17b57837
commit 92fd9ed0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -380,9 +380,10 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
return ret("", false) return ret("", false)
} }
redir := parsed.ResolveReference(parsedMeta).String() redir := parsed.ResolveReference(parsedMeta).String()
justAddsSlash := (redir == u+"/")
// Prompt before redirecting to non-Gemini protocol // Prompt before redirecting to non-Gemini protocol
redirect := false redirect := false
if !strings.HasPrefix(redir, "gemini") { if !justAddsSlash && !strings.HasPrefix(redir, "gemini") {
if YesNo("Follow redirect to non-Gemini URL?\n" + redir) { if YesNo("Follow redirect to non-Gemini URL?\n" + redir) {
redirect = true redirect = true
} else { } else {
@ -390,7 +391,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
} }
} }
// Prompt before redirecting // Prompt before redirecting
autoRedirect := viper.GetBool("a-general.auto_redirect") autoRedirect := justAddsSlash || viper.GetBool("a-general.auto_redirect")
if redirect || (autoRedirect && numRedirects < 5) || YesNo("Follow redirect?\n"+redir) { if redirect || (autoRedirect && numRedirects < 5) || YesNo("Follow redirect?\n"+redir) {
if res.Status == gemini.StatusRedirectPermanent { if res.Status == gemini.StatusRedirectPermanent {
go cache.AddRedir(u, redir) go cache.AddRedir(u, redir)