Update go-gemini
alex wennerberg alex@alexwennerberg.com
Mon, 25 Jan 2021 20:20:59 -0800
M
gemini.go
→
gemini.go
@@ -5,6 +5,7 @@ "bytes"
"crypto/tls" "crypto/x509/pkix" gmi "git.sr.ht/~adnano/go-gemini" + "git.sr.ht/~adnano/go-gemini/certificate" "io" "io/ioutil" "log"@@ -62,7 +63,7 @@ files, err := getIndexFiles(false)
users, err := getActiveUserNames() if err != nil { log.Println(err) - w.WriteHeader(40, "Internal server error") + w.Status(gmi.StatusTemporaryFailure) } data := struct { Host string@@ -91,21 +92,21 @@ fileName := filepath.Clean(r.URL.Path)
if fileName == "/" { fileName = "index.gmi" } else if strings.HasPrefix(fileName, "/"+HiddenFolder) { - w.WriteStatus(gmi.StatusNotFound) + w.Status(gmi.StatusNotFound) return } fullPath := path.Join(c.FilesDirectory, userName, fileName) if fileName == "/gemlog" { // temp hack _, err := os.Stat(path.Join(fullPath, "index.gmi")) if err != nil { - w.SetMediaType("text/gemini") + w.Meta("text/gemini") io.Copy(w, strings.NewReader(generateGemfeedPage(userName))) return } } else if fileName == "/gemlog/atom.xml" { _, err := os.Stat(fullPath) if err != nil { - w.SetMediaType("application/atom+xml") + w.Meta("application/atom+xml") feed := generateFeedFromUser(userName) atomString := feed.toAtomFeed() io.Copy(w, strings.NewReader(atomString))@@ -132,9 +133,9 @@ // is this necc?
err = server.Certificates.Load(c.GeminiCertStore) if err != nil { } - server.CreateCertificate = func(h string) (tls.Certificate, error) { + server.GetCertificate = func(h string) (tls.Certificate, error) { log.Println("Generating certificate for", h) - return gmi.CreateCertificate(gmi.CertificateOptions{ + return certificate.Create(certificate.CreateOptions{ Subject: pkix.Name{ CommonName: h, },@@ -149,11 +150,8 @@ mux.HandleFunc("/", gmiIndex)
var wildcardMux gmi.ServeMux wildcardMux.HandleFunc("/", gmiPage) - server.Register(hostname, &mux) - server.Register("*."+hostname, &wildcardMux) - for k, _ := range domains { // TODO fix - server.Register(k, &wildcardMux) - } + server.Handle(hostname, &mux) + server.Handle("*", &wildcardMux) err = server.ListenAndServe() if err != nil {
M
go.sum
→
go.sum
@@ -12,6 +12,8 @@ git.sr.ht/~adnano/go-gemini v0.1.8 h1:93DxDNXB0bjnfDhZewf+QsEopfuOMh/I4v7ujoJ6WIs=
git.sr.ht/~adnano/go-gemini v0.1.8/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0= git.sr.ht/~adnano/go-gemini v0.1.10 h1:enuYuY2pC+1BsP1GE73wLIyhXc4r+Ryx6TUubynmSgo= git.sr.ht/~adnano/go-gemini v0.1.10/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0= +git.sr.ht/~adnano/go-gemini v0.1.14-0.20210125155540-9e89b93bab84 h1:TEt97hCPo34Hjs8jgfeWqQDnZbM+5ne/5emUipyHu8Y= +git.sr.ht/~adnano/go-gemini v0.1.14-0.20210125155540-9e89b93bab84/go.mod h1:If1VxEWcZDrRt5FeAFnGTcM2Ud1E3BXs3VJ5rnZWKq0= git.sr.ht/~sircmpwn/getopt v0.0.0-20201218204720-9961a9c6298f h1:f5axCdaRzGDCihN3o1Lq0ydn0VlkhY+11G0JOyY5qss= git.sr.ht/~sircmpwn/getopt v0.0.0-20201218204720-9961a9c6298f/go.mod h1:wMEGFFFNuPos7vHmWXfszqImLppbc0wEhh6JBfJIUgw= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
M
http.go
→
http.go
@@ -603,10 +603,12 @@ if !raw && !acceptsGemini && (isGemini(fullPath) || geminiContent != "") {
var htmlString string if geminiContent == "" { file, _ := os.Open(fullPath) - htmlString = textToHTML(nil, gmi.ParseText(file)) + parse, _ := gmi.ParseText(file) + htmlString = textToHTML(nil, parse) defer file.Close() } else { - htmlString = textToHTML(nil, gmi.ParseText(strings.NewReader(geminiContent))) + parse, _ := gmi.ParseText(strings.NewReader(geminiContent)) + htmlString = textToHTML(nil, parse) } favicon := getFavicon(userName) hostname := strings.Split(r.Host, ":")[0]
M
log.go
→
log.go
@@ -159,7 +159,12 @@
// Anonymize user and IP? func logGemini(r *gmi.Request) { - ipAddr := r.RemoteAddr.String() + var ipAddr string + if r.RemoteAddr != nil { + ipAddr = r.RemoteAddr.String() + } else { + ipAddr = "" + } host, _, err := net.SplitHostPort(ipAddr) if err != nil { host = ipAddr
M
proxy.go
→
proxy.go
@@ -37,8 +37,7 @@ } else {
req.URL, err = url.Parse(fmt.Sprintf("gemini://%s/", spath[1])) } client := gemini.Client{ - Timeout: 60 * time.Second, - InsecureSkipTrust: true, + Timeout: 60 * time.Second, } if h := (url.URL{Host: req.Host}); h.Port() == "" {@@ -111,7 +110,8 @@ return
} w.Header().Add("Content-Type", "text/html") - htmlString := textToHTML(req.URL, gemini.ParseText(resp.Body)) + parse, _ := gemini.ParseText(resp.Body) + htmlString := textToHTML(req.URL, parse) if strings.HasSuffix(r.URL.Path, "/") { r.URL.Path = path.Dir(r.URL.Path) }