修复gzip压缩的问题

This commit is contained in:
Liujian
2022-08-02 10:53:59 +08:00
parent ef57db3ea5
commit 8c21ecfcee

View File

@@ -46,7 +46,7 @@ func (r *Response) BodyLen() int {
func (r *Response) GetBody() []byte {
if strings.Contains(r.GetHeader("Content-Encoding"), "gzip") {
body, _ := r.BodyGunzip()
r.Headers().Del("Content-Encoding")
r.DelHeader("Content-Encoding")
r.SetHeader("Content-Length", strconv.Itoa(len(body)))
r.Response.SetBody(body)
}
@@ -54,6 +54,15 @@ func (r *Response) GetBody() []byte {
return r.Response.Body()
}
func (r *Response) SetBody(bytes []byte) {
if strings.Contains(r.GetHeader("Content-Encoding"), "gzip") {
r.DelHeader("Content-Encoding")
}
r.Response.SetBody(bytes)
r.SetHeader("Content-Length", strconv.Itoa(len(bytes)))
r.responseError = nil
}
func (r *Response) StatusCode() int {
if r.responseError != nil {
return 504
@@ -82,9 +91,3 @@ func (r *Response) ProxyStatus() string {
func (r *Response) SetProxyStatus(code int, status string) {
r.proxyStatusCode = code
}
func (r *Response) SetBody(bytes []byte) {
r.Response.SetBody(bytes)
r.SetHeader("Content-Length", strconv.Itoa(len(bytes)))
r.responseError = nil
}