addon/decoder.go

addon-dailer
lqqyt2423 4 years ago
parent 6807cce67d
commit 7c0033654f

@ -0,0 +1,13 @@
package addon
import "github.com/lqqyt2423/go-mitmproxy/flow"
// decode content-encoding then respond to client
type Decoder struct {
Base
}
func (d *Decoder) Response(f *flow.Flow) {
f.Response.ReplaceToDecodedBody()
}

@ -6,6 +6,7 @@ import (
"compress/gzip" "compress/gzip"
"errors" "errors"
"io" "io"
"strconv"
"strings" "strings"
"github.com/andybalholm/brotli" "github.com/andybalholm/brotli"
@ -70,10 +71,16 @@ func (r *Response) DecodedBody() ([]byte, error) {
return r.decodedBody, nil return r.decodedBody, nil
} }
// 当 Response.Body 替换为解压的内容时调用 func (r *Response) ReplaceToDecodedBody() {
func (r *Response) RemoveEncodingHeader() { body, err := r.DecodedBody()
if err != nil || body == nil {
return
}
r.Body = body
r.Header.Del("Content-Encoding") r.Header.Del("Content-Encoding")
r.Header.Del("Content-Length") r.Header.Set("Content-Length", strconv.Itoa(len(body)))
r.Header.Del("Transfer-Encoding")
} }
func Decode(enc string, body []byte) ([]byte, error) { func Decode(enc string, body []byte) ([]byte, error) {

Loading…
Cancel
Save