From 0a75c11b07c3f1c42a3b5280d51574cfcb24957b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E4=B9=9D=E6=AF=9C?= Date: Mon, 17 Aug 2020 16:29:59 +0800 Subject: [PATCH] fix panic wrote more than the declared Content-Length --- context/render.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/context/render.go b/context/render.go index e2fb8256..faaafc23 100644 --- a/context/render.go +++ b/context/render.go @@ -1,22 +1,21 @@ package context import ( + "bytes" "encoding/xml" "net/http" + "io" ) var xmlContentType = []string{"application/xml; charset=utf-8"} var plainContentType = []string{"text/plain; charset=utf-8"} //Render render from bytes -func (ctx *Context) Render(bytes []byte) { +func (ctx *Context) Render(bytes1 []byte) { //debug //fmt.Println("response msg = ", string(bytes)) - ctx.Writer.WriteHeader(200) - _, err := ctx.Writer.Write(bytes) - if err != nil { - panic(err) - } + bytesBuffer := bytes.NewBuffer(bytes1) + io.Copy(ctx.Writer, bytesBuffer) } //String render from string