aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-11-11 19:52:58 +0100
committerFeuerfuchs <git@feuerfuchs.dev>2019-11-11 19:52:58 +0100
commit311e77312b0399aa7f77dbad75c8942e68328f8d (patch)
treebde92d5cdbf97b82f38301528ce1db872010f3f2
parentFix readme (diff)
downloadgopherproxy-311e77312b0399aa7f77dbad75c8942e68328f8d.tar.gz
gopherproxy-311e77312b0399aa7f77dbad75c8942e68328f8d.tar.bz2
gopherproxy-311e77312b0399aa7f77dbad75c8942e68328f8d.zip
Don't show .xml and .asc files in template, update demo URL
-rw-r--r--README.md2
-rw-r--r--gopherproxy.go62
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.
5 5
6gopherproxy is a fork of [https://github.com/prologic/gopherproxy](https://github.com/prologic/gopherproxy). 6gopherproxy is a fork of [https://github.com/prologic/gopherproxy](https://github.com/prologic/gopherproxy).
7 7
8Demo: https://gopher.feuerfuchs.dev/ 8Demo: https://gopher.vulpes.one/
9 9
10 10
11## Requirements 11## 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
86 } 86 }
87 87
88 return tpl.Execute(w, struct { 88 return tpl.Execute(w, struct {
89 Title string 89 Title string
90 URI string 90 URI string
91 Assets AssetList 91 Assets AssetList
92 Lines []Item 92 Lines []Item
93 RawText string 93 RawText string
94 Error bool 94 Error bool
95 }{title, fmt.Sprintf("%s/%s", hostport, uri), assetList, out, "", false}) 95 }{title, fmt.Sprintf("%s/%s", hostport, uri), assetList, out, "", false})
96} 96}
97 97
@@ -126,12 +126,12 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass
126 uri, err := url.QueryUnescape(strings.Join(parts[1:], "/")) 126 uri, err := url.QueryUnescape(strings.Join(parts[1:], "/"))
127 if err != nil { 127 if err != nil {
128 tpl.Execute(w, struct { 128 tpl.Execute(w, struct {
129 Title string 129 Title string
130 URI string 130 URI string
131 Assets AssetList 131 Assets AssetList
132 RawText string 132 RawText string
133 Lines []Item 133 Lines []Item
134 Error bool 134 Error bool
135 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true}) 135 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true})
136 return 136 return
137 } 137 }
@@ -147,12 +147,12 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass
147 147
148 if err != nil { 148 if err != nil {
149 tpl.Execute(w, struct { 149 tpl.Execute(w, struct {
150 Title string 150 Title string
151 URI string 151 URI string
152 Assets AssetList 152 Assets AssetList
153 RawText string 153 RawText string
154 Lines []Item 154 Lines []Item
155 Error bool 155 Error bool
156 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true}) 156 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true})
157 return 157 return
158 } 158 }
@@ -160,17 +160,17 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass
160 if res.Body != nil { 160 if res.Body != nil {
161 if len(parts) < 2 { 161 if len(parts) < 2 {
162 io.Copy(w, res.Body) 162 io.Copy(w, res.Body)
163 } else if parts[1] == "0" { //strings.HasSuffix(uri, ".txt") || strings.HasSuffix(uri, ".md") { 163 } else if parts[1] == "0" && !strings.HasSuffix(uri, ".xml") && !strings.HasSuffix(uri, ".asc") { //strings.HasSuffix(uri, ".txt") || strings.HasSuffix(uri, ".md") {
164 // handle .txt files 164 // handle .txt files
165 buf := new(bytes.Buffer) 165 buf := new(bytes.Buffer)
166 buf.ReadFrom(res.Body) 166 buf.ReadFrom(res.Body)
167 tpl.Execute(w, struct { 167 tpl.Execute(w, struct {
168 Title string 168 Title string
169 URI string 169 URI string
170 Assets AssetList 170 Assets AssetList
171 RawText string 171 RawText string
172 Lines []Item 172 Lines []Item
173 Error bool 173 Error bool
174 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, buf.String(), nil, false}) 174 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, buf.String(), nil, false})
175 } else if parts[1] == "T" { 175 } else if parts[1] == "T" {
176 _, _, err = vips.NewTransform(). 176 _, _, err = vips.NewTransform().
@@ -186,12 +186,12 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, ass
186 } else { 186 } else {
187 if err := renderDirectory(w, tpl, assetList, uri, hostport, res.Dir); err != nil { 187 if err := renderDirectory(w, tpl, assetList, uri, hostport, res.Dir); err != nil {
188 tpl.Execute(w, struct { 188 tpl.Execute(w, struct {
189 Title string 189 Title string
190 URI string 190 URI string
191 Assets AssetList 191 Assets AssetList
192 RawText string 192 RawText string
193 Lines []Item 193 Lines []Item
194 Error bool 194 Error bool
195 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true}) 195 }{uri, fmt.Sprintf("%s/%s", hostport, uri), assetList, fmt.Sprintf("Error: %s", err), nil, true})
196 return 196 return
197 } 197 }