From 30873e1b0bec9fada74e63550658eea2f82495eb Mon Sep 17 00:00:00 2001 From: makeworld Date: Tue, 1 Sep 2020 14:55:52 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20empty=20proxy=20bug,=20sta?= =?UTF-8?q?rt=20on=20#80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- README.md | 3 +-- client/client.go | 4 ++-- config/config.go | 7 ++++--- config/default.go | 31 +++++++++++++++++++++---------- default-config.toml | 31 +++++++++++++++++++++---------- display/private.go | 9 +++++---- 7 files changed, 55 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 598c1b0..fd6a23b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - F1 and F2 keys for navigating to the previous and next tabs (#64) diff --git a/README.md b/README.md index 1ac4a9f..0da03e9 100644 --- a/README.md +++ b/README.md @@ -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* diff --git a/client/client.go b/client/client.go index 857b353..150782b 100644 --- a/client/client.go +++ b/client/client.go @@ -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 diff --git a/config/config.go b/config/config.go index efdbb83..12861d0 100644 --- a/config/config.go +++ b/config/config.go @@ -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") == "" { diff --git a/config/default.go b/config/default.go index 8f68590..f2cbda4 100644 --- a/config/default.go +++ b/config/default.go @@ -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. diff --git a/default-config.toml b/default-config.toml index 272f381..421f3e7 100644 --- a/default-config.toml +++ b/default-config.toml @@ -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. diff --git a/display/private.go b/display/private.go index d0edeb1..efda217 100644 --- a/display/private.go +++ b/display/private.go @@ -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