Commit e8c83663 authored by astaxie's avatar astaxie Committed by GitHub

Merge pull request #2754 from imiskolee/develop

supported gzip for req.Header has `Content-Encoding: gzip`
parents 4901567b 29bcd31b
......@@ -16,6 +16,7 @@ package context
import (
"bytes"
"compress/gzip"
"errors"
"io"
"io/ioutil"
......@@ -350,8 +351,19 @@ func (input *BeegoInput) CopyBody(MaxMemory int64) []byte {
if input.Context.Request.Body == nil {
return []byte{}
}
var requestbody []byte
safe := &io.LimitedReader{R: input.Context.Request.Body, N: MaxMemory}
requestbody, _ := ioutil.ReadAll(safe)
if input.Header("Content-Encoding") == "gzip" {
reader, err := gzip.NewReader(safe)
if err != nil {
return nil
}
requestbody, _ = ioutil.ReadAll(reader)
} else {
requestbody, _ = ioutil.ReadAll(safe)
}
input.Context.Request.Body.Close()
bf := bytes.NewBuffer(requestbody)
input.Context.Request.Body = http.MaxBytesReader(input.Context.ResponseWriter, ioutil.NopCloser(bf), MaxMemory)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment