代码拉取完成,页面将自动刷新
package urlx
import (
"io"
"net/http"
"github.com/andybalholm/brotli"
"github.com/klauspost/compress/flate"
"github.com/klauspost/compress/gzip"
"github.com/klauspost/compress/s2"
"github.com/klauspost/compress/snappy"
"github.com/klauspost/compress/zstd"
)
// DecompressionBody 解压Body
func DecompressionBody(next Process) Process {
return func(resp *http.Response, body io.ReadCloser) (err error) {
defer body.Close()
contentEncoding := resp.Header.Get(HeaderContentEncoding)
if contentEncoding != "" {
decoded := true
switch contentEncoding {
case "br":
body = io.NopCloser(brotli.NewReader(body))
case "deflate":
body = flate.NewReader(body)
case "gzip":
body, err = gzip.NewReader(body)
case "s2":
body = io.NopCloser(s2.NewReader(body))
case "snappy":
body = io.NopCloser(snappy.NewReader(body))
case "zstd":
b, er := zstd.NewReader(body)
if er != nil {
return er
}
body = b.IOReadCloser()
default:
decoded = false
}
if err != nil {
return
}
if decoded {
resp.Header.Del(HeaderContentEncoding)
}
}
return next(resp, io.NopCloser(body))
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。