mirror of
https://code.rocketnine.space/tslocum/gmitohtml.git
synced 2024-11-27 17:38:14 +01:00
Always use lowercase hostname in requests
This commit is contained in:
parent
8c9f7852bb
commit
7445d6c830
2 changed files with 19 additions and 7 deletions
|
@ -10,6 +10,8 @@ conversion tool and daemon
|
||||||
|
|
||||||
[**Download gmitohtml**](https://gmitohtml.rocketnine.space/download/?sort=name&order=desc)
|
[**Download gmitohtml**](https://gmitohtml.rocketnine.space/download/?sort=name&order=desc)
|
||||||
|
|
||||||
|
gmitohtml is available on Android as [Xenia](https://gitlab.com/tslocum/xenia).
|
||||||
|
|
||||||
## Compile
|
## Compile
|
||||||
|
|
||||||
gmitohtml is written in [Go](https://golang.org). Run the following command to
|
gmitohtml is written in [Go](https://golang.org). Run the following command to
|
||||||
|
|
|
@ -26,25 +26,35 @@ func rewriteURL(u string, loc *url.URL) string {
|
||||||
scheme = "file"
|
scheme = "file"
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(u, "gemini://") {
|
if strings.HasPrefix(u, "file://") {
|
||||||
return "http://" + daemonAddress + "/gemini/" + u[9:]
|
|
||||||
} else if strings.HasPrefix(u, "file://") {
|
|
||||||
if !allowFileAccess {
|
if !allowFileAccess {
|
||||||
return "http://" + daemonAddress + "/?FileAccessNotAllowed"
|
return "http://" + daemonAddress + "/?FileAccessNotAllowed"
|
||||||
}
|
}
|
||||||
return "http://" + daemonAddress + "/file/" + u[7:]
|
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, "://") {
|
} else if strings.Contains(u, "://") {
|
||||||
return u
|
return u
|
||||||
} else if loc != nil && len(u) > 0 && !strings.HasPrefix(u, "//") {
|
} else if loc != nil && len(u) > 0 && !strings.HasPrefix(u, "//") {
|
||||||
newPath := u
|
|
||||||
if u[0] != '/' {
|
if u[0] != '/' {
|
||||||
if loc.Path[len(loc.Path)-1] == '/' {
|
if loc.Path[len(loc.Path)-1] == '/' {
|
||||||
newPath = path.Join("/", loc.Path, u)
|
u = path.Join("/", loc.Path, u)
|
||||||
} else {
|
} else {
|
||||||
newPath = path.Join("/", path.Dir(loc.Path), u)
|
u = path.Join("/", path.Dir(loc.Path), u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "http://" + daemonAddress + "/" + scheme + "/" + loc.Host + newPath
|
return "http://" + daemonAddress + "/" + scheme + "/" + strings.ToLower(loc.Host) + u
|
||||||
}
|
}
|
||||||
return "http://" + daemonAddress + "/" + scheme + "/" + u
|
return "http://" + daemonAddress + "/" + scheme + "/" + u
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue