mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-11-25 22:53:02 +03:00
🐛 Make TOFU warning accurate when proxy enabled
This commit is contained in:
parent
b37af27b80
commit
3dfbeb5bda
@ -4,6 +4,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/makeworld-the-better-one/amfora/config"
|
||||||
"github.com/makeworld-the-better-one/go-gemini"
|
"github.com/makeworld-the-better-one/go-gemini"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@ -14,7 +15,7 @@ func Fetch(u string) (*gemini.Response, error) {
|
|||||||
var res *gemini.Response
|
var res *gemini.Response
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if viper.GetString("a-general.proxy") == "" {
|
if config.Proxy == nil {
|
||||||
res, err = gemini.Fetch(u)
|
res, err = gemini.Fetch(u)
|
||||||
} else {
|
} else {
|
||||||
res, err = gemini.FetchWithHost(viper.GetString("a-general.proxy"), u)
|
res, err = gemini.FetchWithHost(viper.GetString("a-general.proxy"), u)
|
||||||
|
@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -30,6 +31,8 @@ var bkmkPath string
|
|||||||
|
|
||||||
var DownloadsDir string
|
var DownloadsDir string
|
||||||
|
|
||||||
|
var Proxy *url.URL
|
||||||
|
|
||||||
//nolint:golint,goerr113
|
//nolint:golint,goerr113
|
||||||
func Init() error {
|
func Init() error {
|
||||||
home, err := homedir.Dir()
|
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_size", 2097152)
|
||||||
viper.SetDefault("a-general.page_max_time", 10)
|
viper.SetDefault("a-general.page_max_time", 10)
|
||||||
viper.SetDefault("a-general.emoji_favicons", false)
|
viper.SetDefault("a-general.emoji_favicons", false)
|
||||||
|
viper.SetDefault("a-general.proxy", "")
|
||||||
viper.SetDefault("keybindings.shift_numbers", "!@#$%^&*()")
|
viper.SetDefault("keybindings.shift_numbers", "!@#$%^&*()")
|
||||||
viper.SetDefault("url-handlers.other", "off")
|
viper.SetDefault("url-handlers.other", "off")
|
||||||
viper.SetDefault("cache.max_size", 0)
|
viper.SetDefault("cache.max_size", 0)
|
||||||
@ -168,6 +172,8 @@ func Init() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Proxy, _ = url.Parse(viper.GetString("a-general.proxy"))
|
||||||
|
|
||||||
// Setup downloads dir
|
// Setup downloads dir
|
||||||
if viper.GetString("a-general.downloads") == "" {
|
if viper.GetString("a-general.downloads") == "" {
|
||||||
// Find default Downloads dir
|
// Find default Downloads dir
|
||||||
|
@ -360,13 +360,25 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, client.ErrTofu) {
|
if errors.Is(err, client.ErrTofu) {
|
||||||
if Tofu(parsed.Host, client.GetExpiry(parsed.Hostname(), parsed.Port())) {
|
if config.Proxy == nil {
|
||||||
// They want to continue anyway
|
if Tofu(parsed.Host, client.GetExpiry(parsed.Hostname(), parsed.Port())) {
|
||||||
client.ResetTofuEntry(parsed.Hostname(), parsed.Port(), res.Cert)
|
// They want to continue anyway
|
||||||
// Response can be used further down, no need to reload
|
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 {
|
} else {
|
||||||
// They don't want to continue
|
// They are using a proxy
|
||||||
return ret("", false)
|
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 {
|
} else if err != nil {
|
||||||
Error("URL Fetch Error", err.Error())
|
Error("URL Fetch Error", err.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user