1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

🐛 Make TOFU warning accurate when proxy enabled

This commit is contained in:
makeworld 2020-09-01 12:56:44 -04:00
parent b37af27b80
commit 3dfbeb5bda
3 changed files with 26 additions and 7 deletions

View File

@ -4,6 +4,7 @@ package client
import (
"net/url"
"github.com/makeworld-the-better-one/amfora/config"
"github.com/makeworld-the-better-one/go-gemini"
"github.com/spf13/viper"
)
@ -14,7 +15,7 @@ func Fetch(u string) (*gemini.Response, error) {
var res *gemini.Response
var err error
if viper.GetString("a-general.proxy") == "" {
if config.Proxy == nil {
res, err = gemini.Fetch(u)
} else {
res, err = gemini.FetchWithHost(viper.GetString("a-general.proxy"), u)

View File

@ -2,6 +2,7 @@ package config
import (
"fmt"
"net/url"
"os"
"path/filepath"
"runtime"
@ -30,6 +31,8 @@ var bkmkPath string
var DownloadsDir string
var Proxy *url.URL
//nolint:golint,goerr113
func Init() error {
home, err := homedir.Dir()
@ -156,6 +159,7 @@ func Init() error {
viper.SetDefault("a-general.page_max_size", 2097152)
viper.SetDefault("a-general.page_max_time", 10)
viper.SetDefault("a-general.emoji_favicons", false)
viper.SetDefault("a-general.proxy", "")
viper.SetDefault("keybindings.shift_numbers", "!@#$%^&*()")
viper.SetDefault("url-handlers.other", "off")
viper.SetDefault("cache.max_size", 0)
@ -168,6 +172,8 @@ func Init() error {
return err
}
Proxy, _ = url.Parse(viper.GetString("a-general.proxy"))
// Setup downloads dir
if viper.GetString("a-general.downloads") == "" {
// Find default Downloads dir

View File

@ -360,13 +360,25 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
}
if errors.Is(err, client.ErrTofu) {
if Tofu(parsed.Host, client.GetExpiry(parsed.Hostname(), parsed.Port())) {
// They want to continue anyway
client.ResetTofuEntry(parsed.Hostname(), parsed.Port(), res.Cert)
// Response can be used further down, no need to reload
if config.Proxy == nil {
if Tofu(parsed.Host, client.GetExpiry(parsed.Hostname(), parsed.Port())) {
// They want to continue anyway
client.ResetTofuEntry(parsed.Hostname(), parsed.Port(), res.Cert)
// Response can be used further down, no need to reload
} else {
// They don't want to continue
return ret("", false)
}
} else {
// They don't want to continue
return ret("", false)
// They are using a proxy
if Tofu(config.Proxy.Host, client.GetExpiry(config.Proxy.Hostname(), config.Proxy.Port())) {
// They want to continue anyway
client.ResetTofuEntry(config.Proxy.Hostname(), config.Proxy.Port(), res.Cert)
// Response can be used further down, no need to reload
} else {
// They don't want to continue
return ret("", false)
}
}
} else if err != nil {
Error("URL Fetch Error", err.Error())