From 311e77312b0399aa7f77dbad75c8942e68328f8d Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Mon, 11 Nov 2019 19:52:58 +0100 Subject: Don't show .xml and .asc files in template, update demo URL --- README.md | 2 +- gopherproxy.go | 62 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index b78d7d2..f4d5cc6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ by proxying standard Web HTTP requests to Gopher requests of the target server. gopherproxy is a fork of [https://github.com/prologic/gopherproxy](https://github.com/prologic/gopherproxy). -Demo: https://gopher.feuerfuchs.dev/ +Demo: https://gopher.vulpes.one/ ## Requirements diff --git a/gopherproxy.go b/gopherproxy.go index 0b3279c..a9396ef 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -86,12 +86,12 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, assetList As } return tpl.Execute(w, struct { - Title string - URI string - Assets AssetList - Lines []Item - RawText string - Error bool + Title string + URI string + Assets AssetList + Lines []Item + RawText string + Error bool }{title, fmt.Sprintf("%s/%s", hostport, uri), assetList, out, "", false}) } @@ -126,12 +126,12 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass uri, err := url.QueryUnescape(strings.Join(parts[1:], "/")) if err != nil { tpl.Execute(w, struct { - Title string - URI string - Assets AssetList - RawText string - Lines []Item - Error bool + Title string + URI string + Assets AssetList + RawText string + Lines []Item + Error bool }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true}) return } @@ -147,12 +147,12 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass if err != nil { tpl.Execute(w, struct { - Title string - URI string - Assets AssetList - RawText string - Lines []Item - Error bool + Title string + URI string + Assets AssetList + RawText string + Lines []Item + Error bool }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true}) return } @@ -160,17 +160,17 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass if res.Body != nil { if len(parts) < 2 { io.Copy(w, res.Body) - } else if parts[1] == "0" { //strings.HasSuffix(uri, ".txt") || strings.HasSuffix(uri, ".md") { + } else if parts[1] == "0" && !strings.HasSuffix(uri, ".xml") && !strings.HasSuffix(uri, ".asc") { //strings.HasSuffix(uri, ".txt") || strings.HasSuffix(uri, ".md") { // handle .txt files buf := new(bytes.Buffer) buf.ReadFrom(res.Body) tpl.Execute(w, struct { - Title string - URI string - Assets AssetList - RawText string - Lines []Item - Error bool + Title string + URI string + Assets AssetList + RawText string + Lines []Item + Error bool }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, buf.String(), nil, false}) } else if parts[1] == "T" { _, _, err = vips.NewTransform(). @@ -186,12 +186,12 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass } else { if err := renderDirectory(w, tpl, assetList, uri, hostport, res.Dir); err != nil { tpl.Execute(w, struct { - Title string - URI string - Assets AssetList - RawText string - Lines []Item - Error bool + Title string + URI string + Assets AssetList + RawText string + Lines []Item + Error bool }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true}) return } -- cgit v1.2.3-54-g00ecf