mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 07:10:55 +00:00
accept encoder header setting fixed
This commit is contained in:
parent
1200b7c347
commit
a9881388f7
@ -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 = ""
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user