~sircmpwn/gmni-devel

kineto: Display an error on charsets other than UTF-8 v1 PROPOSED

Adnan Maolood: 1
 Display an error on charsets other than UTF-8

 1 files changed, 10 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/gmni-devel/patches/20519/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH kineto] Display an error on charsets other than UTF-8 Export this patch

This prevents the proxy from sending invalid UTF-8 to the client.
---
 main.go | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/main.go b/main.go
index 32efb94..47c35d5 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,
-- 
2.30.1