Strip HTTP port from Gopher links
Previously, if running an instance on e.g. http://localhost:8080, the port would show up in the Gopher links and potentially cause rendering to fail. This fixes that.
This commit is contained in:
parent
c0fdd8af49
commit
7257af2905
1 changed files with 7 additions and 1 deletions
|
@ -14,6 +14,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -31,8 +32,13 @@ func initGopher(apper Apper) {
|
||||||
|
|
||||||
// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
|
// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
|
||||||
func stripHostProtocol(app *App) string {
|
func stripHostProtocol(app *App) string {
|
||||||
|
u, err := url.Parse(app.cfg.App.Host)
|
||||||
|
if err != nil {
|
||||||
|
// Fall back to host, with scheme stripped
|
||||||
return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte("")))
|
return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte("")))
|
||||||
}
|
}
|
||||||
|
return u.Hostname()
|
||||||
|
}
|
||||||
|
|
||||||
func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
|
func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
|
||||||
parts := strings.Split(r.Selector, "/")
|
parts := strings.Split(r.Selector, "/")
|
||||||
|
|
Loading…
Add table
Reference in a new issue