1 Star 1 Fork 0

fast_api/api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gzip.go 685 Bytes
一键复制 编辑 原始数据 按行查看 历史
t.io 提交于 2024-01-27 12:27 +08:00 . fix http do flow
package sgzip
import (
"compress/gzip"
"net/http"
"strings"
"gitee.com/fast_api/api/def"
"gitee.com/fast_api/api/intercept"
)
var _ intercept.HttpIntercept = (*GZip)(nil)
type GZip struct{}
// Http implements intercept.HttpIntercept.
func (g *GZip) Http(rw http.ResponseWriter, req *http.Request, ctx *intercept.HttpContext) bool {
if strings.Contains(req.Header.Get(def.Content_Encoding), "gzip") {
reader, err := gzip.NewReader(req.Body)
if err != nil {
rw.WriteHeader(http.StatusBadRequest)
return true
}
req.Body = reader
}
return false
}
// Order implements intercept.HttpIntercept.
func (g *GZip) Order() def.HandlerOrder {
return def.Handler_GZIP
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fast_api/api.git
git@gitee.com:fast_api/api.git
fast_api
api
api
v0.1.0

搜索帮助