From abf5ab340ed76792214ae80c62df7abe0ad1b8a8 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 15 Oct 2019 14:07:10 -0600 Subject: caddyhttp: Improve ResponseRecorder to buffer headers --- modules/caddyhttp/markdown/markdown.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'modules/caddyhttp/markdown/markdown.go') diff --git a/modules/caddyhttp/markdown/markdown.go b/modules/caddyhttp/markdown/markdown.go index 122aad6..5ff18b8 100644 --- a/modules/caddyhttp/markdown/markdown.go +++ b/modules/caddyhttp/markdown/markdown.go @@ -48,8 +48,8 @@ func (m Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht buf.Reset() defer bufPool.Put(buf) - shouldBuf := func(status int) bool { - return strings.HasPrefix(w.Header().Get("Content-Type"), "text/") + shouldBuf := func(status int, header http.Header) bool { + return strings.HasPrefix(header.Get("Content-Type"), "text/") } rec := caddyhttp.NewResponseRecorder(w, buf, shouldBuf) @@ -62,6 +62,8 @@ func (m Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht return nil } + caddyhttp.CopyHeader(w.Header(), rec.Header()) + output := blackfriday.Run(buf.Bytes()) w.Header().Set("Content-Length", strconv.Itoa(len(output))) -- cgit v1.2.3