diff --git a/context/acceptencoder.go b/context/acceptencoder.go index 2d568fc0..c2a79fa1 100644 --- a/context/acceptencoder.go +++ b/context/acceptencoder.go @@ -23,7 +23,6 @@ import ( "strconv" "strings" - "fmt" "io/ioutil" ) @@ -50,7 +49,6 @@ func writeLevel(encoding string, writer io.Writer, content []byte, level int) (b var outputWriter io.Writer var err error if cf, ok := encoderMap[encoding]; ok { - fmt.Println("write level", encoding) outputWriter, err = cf.encode(writer, level) } else { encoding = "" diff --git a/context/output.go b/context/output.go index 454d132e..4d902487 100644 --- a/context/output.go +++ b/context/output.go @@ -52,23 +52,24 @@ func (output *BeegoOutput) Header(key, val string) { // if EnableGzip, compress content string. // it sends out response body directly. func (output *BeegoOutput) Body(content []byte) { - outputWriter := output.Context.ResponseWriter.(io.Writer) var encoding string + var buf = &bytes.Buffer{} if output.EnableGzip { encoding = ParseEncoding(output.Context.Input.Request) } - if b, n, _ := WriteBody(encoding, outputWriter, content); b { + if b, n, _ := WriteBody(encoding, buf, content); b { output.Header("Content-Encoding", n) } else { output.Header("Content-Length", strconv.Itoa(len(content))) } - // Write status code if it has been set manually // Set it to 0 afterwards to prevent "multiple response.WriteHeader calls" if output.Status != 0 { output.Context.ResponseWriter.WriteHeader(output.Status) output.Status = 0 } + + io.Copy(output.Context.ResponseWriter, buf) } // Cookie sets cookie value via given key.