content-encoding deflate support

addon-dailer
lqqyt2423 4 years ago
parent 44d7815e68
commit 9b0ebfaa79

@ -2,6 +2,7 @@ package flow
import (
"bytes"
"compress/flate"
"compress/gzip"
"errors"
"io"
@ -77,24 +78,32 @@ func (r *Response) RemoveEncodingHeader() {
func Decode(enc string, body []byte) ([]byte, error) {
if enc == "gzip" {
zr, err := gzip.NewReader(bytes.NewReader(body))
dreader, err := gzip.NewReader(bytes.NewReader(body))
if err != nil {
return nil, err
}
buf := bytes.NewBuffer(make([]byte, 0))
_, err = io.Copy(buf, zr)
_, err = io.Copy(buf, dreader)
if err != nil {
return nil, err
}
err = zr.Close()
err = dreader.Close()
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} else if enc == "br" {
brr := brotli.NewReader(bytes.NewReader(body))
dreader := brotli.NewReader(bytes.NewReader(body))
buf := bytes.NewBuffer(make([]byte, 0))
_, err := io.Copy(buf, brr)
_, err := io.Copy(buf, dreader)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
} else if enc == "deflate" {
dreader := flate.NewReader(bytes.NewReader(body))
buf := bytes.NewBuffer(make([]byte, 0))
_, err := io.Copy(buf, dreader)
if err != nil {
return nil, err
}

Loading…
Cancel
Save