mirror of
https://github.com/makew0rld/amfora.git
synced 2024-11-03 02:37:23 -05:00
Use new go-gemini to handle invalid status codes, show error modal for out of range ones
Ref #266
This commit is contained in:
parent
790d7ace6c
commit
1c4d13b055
@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- The user's terminal theme colors are used by default (#181)
|
||||
- By default, non-gemini URI schemes are opened in the default application. This requires a config change for previous users, see the [wiki](https://github.com/makeworld-the-better-one/amfora/wiki/Handling-Other-URL-Schemes) (#207)
|
||||
- Windows uses paths set by `XDG` variables over `APPDATA` if they are set (#255)
|
||||
- Treat status codes like 22 as equivalent to 20 as per the latest spec (#266)
|
||||
|
||||
## Removed
|
||||
- Favicon support (#199)
|
||||
@ -41,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Regression where lists would not appear if `bullets = false` (#234, #235)
|
||||
- Support multiple bookmarks with the same name
|
||||
- Cert change message grammar: "an security" -> "a security" (#274)
|
||||
- Display an error modal for status codes that can't be handled
|
||||
|
||||
|
||||
## [1.8.0] - 2021-02-17
|
||||
|
@ -2,6 +2,7 @@ package display
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"net"
|
||||
"net/url"
|
||||
@ -381,12 +382,14 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
|
||||
// Could be a non 20 status code, or a different kind of document
|
||||
|
||||
// Handle each status code
|
||||
switch res.Status {
|
||||
// Except 20, that's handled after the switch
|
||||
status := gemini.CleanStatus(res.Status)
|
||||
switch status {
|
||||
case 10, 11:
|
||||
var userInput string
|
||||
var ok bool
|
||||
|
||||
if res.Status == 10 {
|
||||
if status == 10 {
|
||||
// Regular input
|
||||
userInput, ok = Input(res.Meta, false)
|
||||
} else {
|
||||
@ -423,7 +426,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
|
||||
// Prompt before redirecting
|
||||
autoRedirect := justAddsSlash || viper.GetBool("a-general.auto_redirect")
|
||||
if redirect || (autoRedirect && numRedirects < 5) || YesNo("Follow redirect?\n"+redir) {
|
||||
if res.Status == gemini.StatusRedirectPermanent {
|
||||
if status == gemini.StatusRedirectPermanent {
|
||||
go cache.AddRedir(u, redir)
|
||||
}
|
||||
return ret(handleURL(t, redir, numRedirects+1))
|
||||
@ -468,6 +471,12 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
|
||||
case 62:
|
||||
Error("Certificate Not Valid", escapeMeta(res.Meta))
|
||||
return ret("", false)
|
||||
default:
|
||||
if !gemini.StatusInRange(status) {
|
||||
// Status code not in a valid range
|
||||
Error("Status Code Error", fmt.Sprintf("Out of range status code: %d", status))
|
||||
return ret("", false)
|
||||
}
|
||||
}
|
||||
|
||||
// Status code 20, but not a document that can be displayed
|
||||
|
2
go.mod
2
go.mod
@ -9,7 +9,7 @@ require (
|
||||
github.com/fsnotify/fsnotify v1.4.9 // indirect
|
||||
github.com/gdamore/tcell/v2 v2.3.3
|
||||
github.com/google/go-cmp v0.5.0 // indirect
|
||||
github.com/makeworld-the-better-one/go-gemini v0.11.0
|
||||
github.com/makeworld-the-better-one/go-gemini v0.12.1
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/mitchellh/mapstructure v1.3.1 // indirect
|
||||
github.com/mmcdole/gofeed v1.1.2
|
||||
|
4
go.sum
4
go.sum
@ -138,8 +138,8 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/makeworld-the-better-one/go-gemini v0.11.0 h1:MNGiULJFvcqls9oCy40tE897hDeKvNmEK9i5kRucgQk=
|
||||
github.com/makeworld-the-better-one/go-gemini v0.11.0/go.mod h1:F+3x+R1xeYK90jMtBq+U+8Sh64r2dHleDZ/en3YgSmg=
|
||||
github.com/makeworld-the-better-one/go-gemini v0.12.1 h1:cWHvCHL31Caq3Rm9elCFFoQeyrn92Kv7KummsVxCOFg=
|
||||
github.com/makeworld-the-better-one/go-gemini v0.12.1/go.mod h1:F+3x+R1xeYK90jMtBq+U+8Sh64r2dHleDZ/en3YgSmg=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
|
@ -251,7 +251,9 @@ func getResource(url string) (string, *gemini.Response, error) {
|
||||
return url, nil, err
|
||||
}
|
||||
|
||||
if res.Status == gemini.StatusSuccess {
|
||||
status := gemini.CleanStatus(res.Status)
|
||||
|
||||
if status == gemini.StatusSuccess {
|
||||
// No redirects
|
||||
return url, res, nil
|
||||
}
|
||||
@ -266,8 +268,8 @@ func getResource(url string) (string, *gemini.Response, error) {
|
||||
urls := make([]*urlPkg.URL, 0)
|
||||
|
||||
// Loop through redirects
|
||||
for (res.Status == gemini.StatusRedirectPermanent || res.Status == gemini.StatusRedirectTemporary) && i < 5 {
|
||||
redirs = append(redirs, res.Status)
|
||||
for (status == gemini.StatusRedirectPermanent || status == gemini.StatusRedirectTemporary) && i < 5 {
|
||||
redirs = append(redirs, status)
|
||||
urls = append(urls, parsed)
|
||||
|
||||
tmp, err := parsed.Parse(res.Meta)
|
||||
@ -302,7 +304,7 @@ func getResource(url string) (string, *gemini.Response, error) {
|
||||
if i < 5 {
|
||||
// The server stopped redirecting after <5 redirects
|
||||
|
||||
if res.Status == gemini.StatusSuccess {
|
||||
if status == gemini.StatusSuccess {
|
||||
// It ended by succeeding
|
||||
|
||||
for j := range redirs {
|
||||
|
Loading…
Reference in New Issue
Block a user