Display an error on charsets other than UTF-8
This prevents the proxy from sending invalid UTF-8 to the client.
This commit is contained in:
parent
6d23d00a6f
commit
a584df6afa
1 changed files with 10 additions and 2 deletions
12
main.go
12
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,
|
||||
|
|
Loading…
Reference in a new issue