🐛 Fix empty proxy bug, start on #80

This commit is contained in:
makeworld 2020-09-01 14:55:52 -04:00
parent 6a8df9c8cf
commit 30873e1b0b
7 changed files with 55 additions and 32 deletions

View File

@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- **Proxy support** - specify a proxy in the config for all requests to go through it (#66)
- **Proxy support** - see the `[proxies]` section in the config (#66, #80)
- **Emoji favicons** can now be seen if `emoji_favicons` is enabled in the config (#62)
- The `shift_numbers` key in the config was added, so that non US keyboard users can navigate tabs (#64)
- <kbd>F1</kbd> and <kbd>F2</kbd> keys for navigating to the previous and next tabs (#64)

View File

@ -100,8 +100,7 @@ Features in *italics* are in the master branch, but not in the latest release.
- [x] *Emoji favicons*
- See `gemini://mozz.us/files/rfc_gemini_favicon.gmi` for details
- [x] *Proxying*
- All requests can optionally be sent through another server
- A gemini proxy server implementation currently does not exist, but Amfora will support it when it does!
- Schemes like Gopher or HTTP can be proxied through a Gemini server
- [ ] Subscribe to RSS and Atom feeds and display them
- Subscribing to page changes, similar to how Spacewalk works, will also be supported
- *In progress on `feeds` branch*

View File

@ -15,10 +15,10 @@ func Fetch(u string) (*gemini.Response, error) {
var res *gemini.Response
var err error
if config.Proxy == nil {
if config.GemProxy == nil {
res, err = gemini.Fetch(u)
} else {
res, err = gemini.FetchWithHost(viper.GetString("a-general.proxy"), u)
res, err = gemini.FetchWithHost(viper.GetString("proxies.gemini"), u)
}
if err != nil {
return nil, err

View File

@ -34,7 +34,7 @@ var bkmkPath string
var DownloadsDir string
var Proxy *url.URL
var GemProxy *url.URL
//nolint:golint,goerr113
func Init() error {
@ -169,7 +169,6 @@ 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)
@ -182,7 +181,9 @@ func Init() error {
return err
}
Proxy, _ = url.Parse(viper.GetString("a-general.proxy"))
if viper.GetString("proxies.gemini") != "" {
GemProxy, _ = url.Parse(viper.GetString("proxies.gemini"))
}
// Setup downloads dir
if viper.GetString("a-general.downloads") == "" {

View File

@ -21,8 +21,8 @@ home = "gemini://gemini.circumlunar.space"
# If set to false, a prompt will be shown before following redirects.
auto_redirect = false
# What command to run to open a HTTP URL. Set to "default" to try to guess the browser,
# or set to "off" to not open HTTP URLs.
# What command to run to open a HTTP(S) URL. Set to "default" to try to guess the browser,
# or set to "off" to not open HTTP(S) URLs.
# If a command is set, than the URL will be added (in quotes) to the end of the command.
# A space will be prepended if necessary.
http = "default"
@ -55,12 +55,6 @@ page_max_time = 10
# Whether to replace tab numbers with emoji favicons, which are cached.
emoji_favicons = false
# Proxy server, through which all requests would be sent.
# String should be a host: a domain/IP with an optional port. Port 1965 is assumed otherwise.
# The proxy server needs to be a Gemini server that supports proxying.
# By default it is empty, which disables the proxy.
proxy = ""
[keybindings]
# In the future there will be more settings here.
@ -74,10 +68,13 @@ shift_numbers = "!@#$%^&*()"
# Allows setting the commands to run for various URL schemes.
# E.g. to open FTP URLs with FileZilla set the following key:
# ftp = "filezilla"
# You can set any scheme to "off" to disable handling it.
# You can set any scheme to "off" or "" to disable handling it, or
# just leave the key unset.
#
# DO NOT use this for setting the HTTP command.
# Use the http setting in the "a-general" section above
# Use the http setting in the "a-general" section above.
#
# NOTE: These settings are override by the ones in the proxies section.
# This is a special key that defines the handler for all URL schemes for which
# no handler is defined.
@ -93,6 +90,20 @@ max_size = 0 # Size in bytes
max_pages = 30 # The maximum number of pages the cache will store
[proxies]
# Allows setting a Gemini proxy for different schemes.
# The settings are similar to the url-handlers section above.
# E.g. to open a gopher page by connecting to a Gemini proxy server:
# gopher = "example.com:123"
#
# Port 1965 is assumed if no port is specified.
#
# NOTE: These settings override any external handlers specified in
# the url-handlers section.
#
# Note that HTTP and HTTPS are treated as separate protocols here.
[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.

View File

@ -18,8 +18,8 @@ home = "gemini://gemini.circumlunar.space"
# If set to false, a prompt will be shown before following redirects.
auto_redirect = false
# What command to run to open a HTTP URL. Set to "default" to try to guess the browser,
# or set to "off" to not open HTTP URLs.
# What command to run to open a HTTP(S) URL. Set to "default" to try to guess the browser,
# or set to "off" to not open HTTP(S) URLs.
# If a command is set, than the URL will be added (in quotes) to the end of the command.
# A space will be prepended if necessary.
http = "default"
@ -52,12 +52,6 @@ page_max_time = 10
# Whether to replace tab numbers with emoji favicons, which are cached.
emoji_favicons = false
# Proxy server, through which all requests would be sent.
# String should be a host: a domain/IP with an optional port. Port 1965 is assumed otherwise.
# The proxy server needs to be a Gemini server that supports proxying.
# By default it is empty, which disables the proxy.
proxy = ""
[keybindings]
# In the future there will be more settings here.
@ -71,10 +65,13 @@ shift_numbers = "!@#$%^&*()"
# Allows setting the commands to run for various URL schemes.
# E.g. to open FTP URLs with FileZilla set the following key:
# ftp = "filezilla"
# You can set any scheme to "off" to disable handling it.
# You can set any scheme to "off" or "" to disable handling it, or
# just leave the key unset.
#
# DO NOT use this for setting the HTTP command.
# Use the http setting in the "a-general" section above
# Use the http setting in the "a-general" section above.
#
# NOTE: These settings are override by the ones in the proxies section.
# This is a special key that defines the handler for all URL schemes for which
# no handler is defined.
@ -90,6 +87,20 @@ max_size = 0 # Size in bytes
max_pages = 30 # The maximum number of pages the cache will store
[proxies]
# Allows setting a Gemini proxy for different schemes.
# The settings are similar to the url-handlers section above.
# E.g. to open a gopher page by connecting to a Gemini proxy server:
# gopher = "example.com:123"
#
# Port 1965 is assumed if no port is specified.
#
# NOTE: These settings override any external handlers specified in
# the url-handlers section.
#
# Note that HTTP and HTTPS are treated as separate protocols here.
[theme]
# This section is for changing the COLORS used in Amfora.
# These colors only apply if 'color' is enabled above.

View File

@ -163,10 +163,11 @@ func handleHTTP(u string, showInfo bool) {
}
// handleOther is used by handleURL.
// It opens links other than Gemini and HTTP and displays Error modals.
// It opens or proxies links other than Gemini and HTTP and displays Error modals.
func handleOther(u string) {
// The URL should have a scheme due to a previous call to normalizeURL
parsed, _ := url.Parse(u)
// Search for a handler for the URL scheme
handler := strings.TrimSpace(viper.GetString("url-handlers." + parsed.Scheme))
if len(handler) == 0 {
@ -360,7 +361,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
}
if errors.Is(err, client.ErrTofu) {
if config.Proxy == nil {
if config.GemProxy == nil {
if Tofu(parsed.Host, client.GetExpiry(parsed.Hostname(), parsed.Port())) {
// They want to continue anyway
client.ResetTofuEntry(parsed.Hostname(), parsed.Port(), res.Cert)
@ -371,9 +372,9 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
}
} else {
// They are using a proxy
if Tofu(config.Proxy.Host, client.GetExpiry(config.Proxy.Hostname(), config.Proxy.Port())) {
if Tofu(config.GemProxy.Host, client.GetExpiry(config.GemProxy.Hostname(), config.GemProxy.Port())) {
// They want to continue anyway
client.ResetTofuEntry(config.Proxy.Hostname(), config.Proxy.Port(), res.Cert)
client.ResetTofuEntry(config.GemProxy.Hostname(), config.GemProxy.Port(), res.Cert)
// Response can be used further down, no need to reload
} else {
// They don't want to continue