增加基础响应数据重写
This commit is contained in:
parent
1f3456a7e1
commit
d9e202001b
@ -8,6 +8,7 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -15,8 +16,6 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/gopkg/safe"
|
||||
)
|
||||
|
||||
// Forward 正向代理的实现
|
||||
@ -61,6 +60,9 @@ func Forward(rw http.ResponseWriter, req *http.Request, serverConfig *Server) {
|
||||
// step 3
|
||||
for key, value := range res.Header {
|
||||
for _, v := range value {
|
||||
if strings.ToLower(key) == "content-encoding" {
|
||||
continue
|
||||
}
|
||||
rw.Header().Add(key, v)
|
||||
}
|
||||
}
|
||||
@ -81,9 +83,9 @@ func Forward(rw http.ResponseWriter, req *http.Request, serverConfig *Server) {
|
||||
gzipData, err = gzip.NewReader(res.Body)
|
||||
responseData, err = ioutil.ReadAll(gzipData)
|
||||
fmt.Println(string(responseData), err)
|
||||
formatData, _ := safe.Filter(responseData, serverConfig.RewriteResponseData)
|
||||
rw.Write(formatData)
|
||||
}
|
||||
|
||||
bytesBuffer := bytes.NewReader([]byte(`{"data":{"permission":true}}`))
|
||||
io.Copy(rw, bytesBuffer)
|
||||
}
|
||||
res.Body.Close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user