From a44a063c1a60ca11066d21d49aca95cfed7d3499 Mon Sep 17 00:00:00 2001 From: tjp Date: Tue, 9 Jan 2024 09:53:15 -0700 Subject: mimetype handling upon general navigation: 1. check for any configured handlers for the mimetype 2. normal printing for gophermap, gemtext, and text/plain 3. save the file to downloads folder --- handlers.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'handlers.go') diff --git a/handlers.go b/handlers.go index d918fd0..64ea5c0 100644 --- a/handlers.go +++ b/handlers.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "mime" + "net/http" "net/url" "strings" @@ -57,6 +58,14 @@ func docType(u *url.URL, response *sliderule.Response) string { } } + if u.Scheme == "http" || u.Scheme == "https" { + resp := response.Meta.(*http.Response) + mtype, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err == nil { + return mtype + } + } + return "text/plain" } -- cgit v1.2.3