Allows for relative redirects

This commit is contained in:
Sloom Sloum Sluom IV 2020-07-02 14:47:38 -07:00
parent 6b2ccc5ad4
commit d7a65e6679
2 changed files with 9 additions and 2 deletions

View File

@ -999,6 +999,13 @@ func (c *client) handleGemini(u Url) {
if strings.Replace(lowerRedirect, lowerOriginal, "", 1) == "/" {
c.Visit(capsule.Content)
} else {
if !strings.Contains(capsule.Content, "://") {
lnk, lnkErr := gemini.HandleRelativeUrl(capsule.Content, u.Full)
if lnkErr == nil {
capsule.Content = lnk
}
}
c.SetMessage(fmt.Sprintf("Follow redirect (y/n): %s?", capsule.Content), false)
c.DrawMessage()
ch := cui.Getch()

View File

@ -399,7 +399,7 @@ func parseGemini(b, currentUrl string) (string, []string) {
}
if strings.Index(link, "://") < 0 {
link, _ = handleRelativeUrl(link, currentUrl)
link, _ = HandleRelativeUrl(link, currentUrl)
}
links = append(links, link)
@ -418,7 +418,7 @@ func parseGemini(b, currentUrl string) (string, []string) {
}
// handleRelativeUrl provides link completion
func handleRelativeUrl(relLink, current string) (string, error) {
func HandleRelativeUrl(relLink, current string) (string, error) {
base, err := url.Parse(current)
if err != nil {
return relLink, err