-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.go
42 lines (37 loc) · 973 Bytes
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"mitmcomp/transcoder"
"strconv"
"strings"
"github.com/lqqyt2423/go-mitmproxy/proxy"
)
type MinifyAddon struct {
proxy.BaseAddon
}
func (a *MinifyAddon) Response(f *proxy.Flow) {
originalSize := len(f.Response.Body)
if strings.Contains(f.Response.Header.Get("Content-Type"), "image/") {
// 画像の圧縮
transcoder.ImgRecompress(f, *imgQuality)
if *debugMode {
debug(originalSize, len(f.Response.Body), "img", f)
}
minifyLog(originalSize, len(f.Response.Body), f.Request.URL)
} else {
if *brotliComp {
// brotliで再圧縮
if err := transcoder.Recompress(f); err != nil {
return
}
if *debugMode {
debug(originalSize, len(f.Response.Body), "brotli", f)
}
minifyLog(originalSize, len(f.Response.Body), f.Request.URL)
} else {
return
}
}
// ヘッダーの書き換え
f.Response.Header.Del("Content-Length")
f.Response.Header.Add("Content-Length", strconv.Itoa(len(f.Response.Body)))
}