From 717c6f65fcdc2ec28f0939473f333ee4b084e4c5 Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Fri, 30 Nov 2018 14:48:29 +0100 Subject: [PATCH] Use a buffer in Render --- context.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index ee7116a..e6cc4b3 100644 --- a/context.go +++ b/context.go @@ -1,7 +1,9 @@ package router import ( + "bytes" "encoding/json" + "io" "net/http" "github.com/julienschmidt/httprouter" @@ -76,9 +78,16 @@ func (c *Context) Render(code int, template string, data interface{}) error { panic(`Cannot call render without a renderer set`) } + var b bytes.Buffer + err := c.router.Renderer.Render(&b, template, data, c) + if err != nil { + return err + } + c.Response.Header().Set(`Content-Type`, `text/html`) c.Response.WriteHeader(code) - return c.router.Renderer.Render(c.Response, template, data, c) + _, _ = io.Copy(c.Response, &b) + return nil } // Set sets a value in the context. Set is not safe to be used concurrently