Selaa lähdekoodia

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.
pull/458/head
Matt Baer 3 vuotta sitten
vanhempi
commit
7257af2905
1 muutettua tiedostoa jossa 7 lisäystä ja 1 poistoa
  1. +7
    -1
      gopher.go

+ 7
- 1
gopher.go Näytä tiedosto

@@ -14,6 +14,7 @@ import (
"bytes"
"fmt"
"io"
"net/url"
"regexp"
"strings"

@@ -31,7 +32,12 @@ func initGopher(apper Apper) {

// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
func stripHostProtocol(app *App) string {
return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte("")))
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 u.Hostname()
}

func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error {


Ladataan…
Peruuta
Tallenna