mirror of
https://code.rocketnine.space/tslocum/gmitohtml.git
synced 2024-11-27 13:38:14 +01:00
Fix connection issue affecting some sites
This commit is contained in:
parent
f933e9dd1b
commit
a23ad13fd8
2 changed files with 48 additions and 39 deletions
|
@ -1,5 +1,9 @@
|
||||||
1.0.4:
|
1.0.5:
|
||||||
- Add option ConvertImages (thanks to @f)
|
- Add option ConvertImages (thanks to @f)
|
||||||
|
- Fix connection issue affecting some sites
|
||||||
|
|
||||||
|
1.0.4:
|
||||||
|
- Migrate to code.rocketnine.space
|
||||||
|
|
||||||
1.0.3:
|
1.0.3:
|
||||||
- Add hostname option
|
- Add hostname option
|
||||||
|
|
|
@ -22,45 +22,50 @@ var assetLock sync.Mutex
|
||||||
var imageExtensions = []string{"png", "jpg", "jpeg", "gif", "svg", "webp"}
|
var imageExtensions = []string{"png", "jpg", "jpeg", "gif", "svg", "webp"}
|
||||||
|
|
||||||
func rewriteURL(u string, loc *url.URL) string {
|
func rewriteURL(u string, loc *url.URL) string {
|
||||||
if daemonAddress != "" {
|
if daemonAddress == "" {
|
||||||
scheme := "gemini"
|
return u
|
||||||
if strings.HasPrefix(loc.Path, "/file/") {
|
|
||||||
scheme = "file"
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(u, "file://") {
|
|
||||||
if !allowFileAccess {
|
|
||||||
return "http://" + daemonAddress + "/?FileAccessNotAllowed"
|
|
||||||
}
|
|
||||||
return "http://" + daemonAddress + "/file/" + u[7:]
|
|
||||||
}
|
|
||||||
|
|
||||||
offset := 0
|
|
||||||
if strings.HasPrefix(u, "gemini://") {
|
|
||||||
offset = 9
|
|
||||||
}
|
|
||||||
firstSlash := strings.IndexRune(u[offset:], '/')
|
|
||||||
if firstSlash != -1 {
|
|
||||||
u = strings.ToLower(u[:firstSlash+offset]) + u[firstSlash+offset:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(u, "gemini://") {
|
|
||||||
return "http://" + daemonAddress + "/gemini/" + u[9:]
|
|
||||||
} else if strings.Contains(u, "://") {
|
|
||||||
return u
|
|
||||||
} else if loc != nil && len(u) > 0 && !strings.HasPrefix(u, "//") {
|
|
||||||
if u[0] != '/' {
|
|
||||||
if loc.Path[len(loc.Path)-1] == '/' {
|
|
||||||
u = path.Join("/", loc.Path, u)
|
|
||||||
} else {
|
|
||||||
u = path.Join("/", path.Dir(loc.Path), u)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "http://" + daemonAddress + "/" + scheme + "/" + strings.ToLower(loc.Host) + u
|
|
||||||
}
|
|
||||||
return "http://" + daemonAddress + "/" + scheme + "/" + u
|
|
||||||
}
|
}
|
||||||
return u
|
|
||||||
|
if loc.Path == "" {
|
||||||
|
loc.Path = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
scheme := "gemini"
|
||||||
|
if strings.HasPrefix(loc.Path, "/file/") {
|
||||||
|
scheme = "file"
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(u, "file://") {
|
||||||
|
if !allowFileAccess {
|
||||||
|
return "http://" + daemonAddress + "/?FileAccessNotAllowed"
|
||||||
|
}
|
||||||
|
return "http://" + daemonAddress + "/file/" + u[7:]
|
||||||
|
}
|
||||||
|
|
||||||
|
offset := 0
|
||||||
|
if strings.HasPrefix(u, "gemini://") {
|
||||||
|
offset = 9
|
||||||
|
}
|
||||||
|
firstSlash := strings.IndexRune(u[offset:], '/')
|
||||||
|
if firstSlash != -1 {
|
||||||
|
u = strings.ToLower(u[:firstSlash+offset]) + u[firstSlash+offset:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(u, "gemini://") {
|
||||||
|
return "http://" + daemonAddress + "/gemini/" + u[9:]
|
||||||
|
} else if strings.Contains(u, "://") {
|
||||||
|
return u
|
||||||
|
} else if loc != nil && len(u) > 0 && !strings.HasPrefix(u, "//") {
|
||||||
|
if u[0] != '/' {
|
||||||
|
if loc.Path[len(loc.Path)-1] == '/' {
|
||||||
|
u = path.Join("/", loc.Path, u)
|
||||||
|
} else {
|
||||||
|
u = path.Join("/", path.Dir(loc.Path), u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "http://" + daemonAddress + "/" + scheme + "/" + strings.ToLower(loc.Host) + u
|
||||||
|
}
|
||||||
|
return "http://" + daemonAddress + "/" + scheme + "/" + u
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPage() []byte {
|
func newPage() []byte {
|
||||||
|
|
Loading…
Reference in a new issue