Fix mediaType for feed.xml over gemini

This commit is contained in:
Brian Picciano 2023-02-13 17:52:17 +01:00
parent 8108d55c29
commit 7d48d2abba
2 changed files with 30 additions and 0 deletions

View File

@ -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

17
src/gmi/util.go Normal file
View File

@ -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}
}