aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdnan Maolood <me@adnano.co>2021-02-24 18:22:01 -0500
committerDrew DeVault <sir@cmpwn.com>2021-02-25 08:51:45 -0500
commita584df6afa719cd9b9f0b70b9265cf65febfd8ec (patch)
tree80a5a34100a928f181809f9cadf4320f969c332a
parentFix relative redirects (diff)
downloadkineto-a584df6afa719cd9b9f0b70b9265cf65febfd8ec.tar.bz2
kineto-a584df6afa719cd9b9f0b70b9265cf65febfd8ec.zip
Display an error on charsets other than UTF-8
This prevents the proxy from sending invalid UTF-8 to the client.
-rw-r--r--main.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/main.go b/main.go
index bbfac30..f836415 100644
--- a/main.go
+++ b/main.go
@@ -453,8 +453,7 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
return
}
- // XXX: We could use the params I guess
- m, _, err := mime.ParseMediaType(resp.Meta)
+ m, params, err := mime.ParseMediaType(resp.Meta)
if err != nil {
w.WriteHeader(http.StatusBadGateway)
w.Write([]byte(fmt.Sprintf("Gateway error: %d %s: %v",
@@ -468,6 +467,15 @@ func proxyGemini(req gemini.Request, external bool, root *url.URL,
return
}
+ if charset, ok := params["charset"]; ok {
+ charset = strings.ToLower(charset)
+ if charset != "utf-8" {
+ w.WriteHeader(http.StatusNotImplemented)
+ fmt.Fprintf(w, "Unsupported charset: %s", charset)
+ return
+ }
+ }
+
w.Header().Add("Content-Type", "text/html")
ctx := &GemtextContext{
CSS: css,