-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (35 loc) · 937 Bytes
/
main.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
43
44
45
package main
import (
"regexp"
"strconv"
"strings"
"github.com/RickLeee/go-mitmproxy/proxy"
log "github.com/sirupsen/logrus"
)
var titleRegexp = regexp.MustCompile("(<title>)(.*?)(</title>)")
type ChangeHtml struct {
proxy.BaseAddon
}
func (c *ChangeHtml) Response(f *proxy.Flow) {
contentType := f.Response.Header.Get("Content-Type")
if !strings.Contains(contentType, "text/html") {
return
}
// change html <title> end with: " - go-mitmproxy"
f.Response.ReplaceToDecodedBody()
f.Response.Body = titleRegexp.ReplaceAll(f.Response.Body, []byte("${1}${2} - go-mitmproxy${3}"))
f.Response.Header.Set("Content-Length", strconv.Itoa(len(f.Response.Body)))
}
func main() {
opts := &proxy.Options{
Addr: ":8080",
StreamLargeBodies: 1024 * 1024 * 5,
SslInsecure: true,
}
p, err := proxy.NewProxy(opts)
if err != nil {
log.Fatal(err)
}
//p.AddAddon(&ChangeHtml{})
log.Fatal(p.Start())
}