fix path issues for proxy server
alex wennerberg alex@alexwennerberg.com
Thu, 07 Jan 2021 00:07:08 -0800
4 files changed,
8 insertions(+),
8 deletions(-)
M
gmi2html.go
→
gmi2html.go
@@ -9,7 +9,7 @@
"git.sr.ht/~adnano/go-gemini" ) -func textToHTML(text gemini.Text) string { +func textToHTML(reqUrl *url.URL, text gemini.Text) string { var b strings.Builder var pre bool var list bool@@ -32,7 +32,8 @@ u, err := url.Parse(urlstring)
if err != nil { continue } - if u.Scheme == "gemini" { + u = reqUrl.ResolveReference(u) + if u.Scheme == "gemini" || u.Scheme == "" { if strings.HasSuffix(u.Host, c.Host) { u.Scheme = "" urlstring = html.EscapeString(u.String())
M
http.go
→
http.go
@@ -586,14 +586,14 @@ if !raw && !acceptsGemini && (isGemini(fullPath) || geminiContent != "") {
var htmlString string if geminiContent == "" { file, _ := os.Open(fullPath) - htmlString = textToHTML(gmi.ParseText(file)) + htmlString = textToHTML(nil, gmi.ParseText(file)) defer file.Close() } else { - htmlString = textToHTML(gmi.ParseText(strings.NewReader(geminiContent))) + htmlString = textToHTML(nil, gmi.ParseText(strings.NewReader(geminiContent))) } favicon := getFavicon(userName) hostname := strings.Split(r.Host, ":")[0] - URI := hostname + r.URL.String() + URI := "gemini://" + hostname + r.URL.String() data := struct { SiteBody template.HTML Favicon string
M
proxy.go
→
proxy.go
@@ -33,7 +33,6 @@ client := gemini.Client{
Timeout: 60 * time.Second, InsecureSkipTrust: true, } - fmt.Println(req) if h := (url.URL{Host: req.Host}); h.Port() == "" { req.Host += ":1965"@@ -106,7 +105,7 @@ }
w.Header().Add("Content-Type", "text/html") - htmlString := textToHTML(gemini.ParseText(resp.Body)) + htmlString := textToHTML(req.URL, gemini.ParseText(resp.Body)) data := struct { SiteBody template.HTML Favicon string
M
templates/user_page.html
→
templates/user_page.html
@@ -12,7 +12,7 @@ <main>
{{.SiteBody}} <br> <div class="footer"> - Proxied from the original at <a href="gemini://{{.URI}}">gemini://{{.URI}}</a> (<a href="https://admin.flounder.online/gemini.gmi">about Gemini</a>) <a href="./?raw=1">raw</a></div> + Proxied from the original at <a href="{{.URI}}">{{.URI}}</a> (<a href="https://admin.flounder.online/gemini.gmi">about Gemini</a>) <a href="./?raw=1">raw</a></div> </main> </body> </html>