1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 19:00:55 +00:00

accept encoder header setting fixed

This commit is contained in:
JessonChan 2015-11-12 10:08:57 +08:00
parent 1200b7c347
commit a9881388f7
2 changed files with 4 additions and 5 deletions

View File

@ -23,7 +23,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"fmt"
"io/ioutil" "io/ioutil"
) )
@ -50,7 +49,6 @@ func writeLevel(encoding string, writer io.Writer, content []byte, level int) (b
var outputWriter io.Writer var outputWriter io.Writer
var err error var err error
if cf, ok := encoderMap[encoding]; ok { if cf, ok := encoderMap[encoding]; ok {
fmt.Println("write level", encoding)
outputWriter, err = cf.encode(writer, level) outputWriter, err = cf.encode(writer, level)
} else { } else {
encoding = "" encoding = ""

View File

@ -52,23 +52,24 @@ func (output *BeegoOutput) Header(key, val string) {
// if EnableGzip, compress content string. // if EnableGzip, compress content string.
// it sends out response body directly. // it sends out response body directly.
func (output *BeegoOutput) Body(content []byte) { func (output *BeegoOutput) Body(content []byte) {
outputWriter := output.Context.ResponseWriter.(io.Writer)
var encoding string var encoding string
var buf = &bytes.Buffer{}
if output.EnableGzip { if output.EnableGzip {
encoding = ParseEncoding(output.Context.Input.Request) 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) output.Header("Content-Encoding", n)
} else { } else {
output.Header("Content-Length", strconv.Itoa(len(content))) output.Header("Content-Length", strconv.Itoa(len(content)))
} }
// Write status code if it has been set manually // Write status code if it has been set manually
// Set it to 0 afterwards to prevent "multiple response.WriteHeader calls" // Set it to 0 afterwards to prevent "multiple response.WriteHeader calls"
if output.Status != 0 { if output.Status != 0 {
output.Context.ResponseWriter.WriteHeader(output.Status) output.Context.ResponseWriter.WriteHeader(output.Status)
output.Status = 0 output.Status = 0
} }
io.Copy(output.Context.ResponseWriter, buf)
} }
// Cookie sets cookie value via given key. // Cookie sets cookie value via given key.