Merge pull request 'Updates `handleGemini` to allow for handling relative redirects' (#182) from fixes-relative-redirects into release2.3.2

Reviewed-on: #182
This commit is contained in:
Sloom Sloum Sluom IV 2020-07-10 00:38:28 -04:00
commit a346d78c7b
2 changed files with 9 additions and 2 deletions

View File

@ -1001,6 +1001,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

@ -404,7 +404,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)
@ -423,7 +423,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