From 7d48d2abba46570ad67fa9f4b8c0b4e023fc2eed Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Mon, 13 Feb 2023 17:52:17 +0100 Subject: Fix mediaType for feed.xml over gemini --- src/gmi/gmi.go | 13 +++++++++++++ src/gmi/util.go | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/gmi/util.go diff --git a/src/gmi/gmi.go b/src/gmi/gmi.go index c2a32aa..115f379 100644 --- a/src/gmi/gmi.go +++ b/src/gmi/gmi.go @@ -161,6 +161,18 @@ func indexMiddleware(h gemini.Handler) gemini.Handler { }) } +func feedMiddleware(h gemini.Handler) gemini.Handler { + + return gemini.HandlerFunc(func( + ctx context.Context, + rw gemini.ResponseWriter, + r *gemini.Request, + ) { + rw = forceResponseWriterMediaType(rw, "application/atom+xml") + h.ServeGemini(ctx, rw, r) + }) +} + func postsMiddleware(tplHandler gemini.Handler) gemini.Handler { return gemini.HandlerFunc(func( @@ -228,6 +240,7 @@ func (a *api) handler() (gemini.Handler, error) { mux := new(gemini.Mux) mux.Handle("/posts/", postsMiddleware(tplHandler)) mux.Handle("/assets/", a.assetsMiddleware()) + mux.Handle("/feed.xml", feedMiddleware(tplHandler)) mux.Handle("/", tplHandler) var h gemini.Handler diff --git a/src/gmi/util.go b/src/gmi/util.go new file mode 100644 index 0000000..b632a54 --- /dev/null +++ b/src/gmi/util.go @@ -0,0 +1,17 @@ +package gmi + +import "git.sr.ht/~adnano/go-gemini" + +type rwSetMediaTypeNoop struct { + gemini.ResponseWriter +} + +func (rwSetMediaTypeNoop) SetMediaType(string) {} + +func forceResponseWriterMediaType( + rw gemini.ResponseWriter, mediaType string, +) gemini.ResponseWriter { + + rw.SetMediaType(mediaType) + return rwSetMediaTypeNoop{rw} +} -- cgit v1.2.3