From 4437768161404a3f521976f95a59b029289d862f Mon Sep 17 00:00:00 2001 From: lqqyt2423 <974923609@qq.com> Date: Tue, 28 Sep 2021 14:27:13 +0800 Subject: [PATCH] example: add http-add-header --- examples/http-add-header/main.go | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/http-add-header/main.go diff --git a/examples/http-add-header/main.go b/examples/http-add-header/main.go new file mode 100644 index 0000000..79f8b26 --- /dev/null +++ b/examples/http-add-header/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "strconv" + + log "github.com/sirupsen/logrus" + + "github.com/lqqyt2423/go-mitmproxy/addon" + "github.com/lqqyt2423/go-mitmproxy/flow" + "github.com/lqqyt2423/go-mitmproxy/proxy" +) + +type AddHeader struct { + addon.Base + count int +} + +func (a *AddHeader) Responseheaders(f *flow.Flow) { + a.count += 1 + f.Response.Header.Add("x-count", strconv.Itoa(a.count)) +} + +func main() { + opts := &proxy.Options{ + Addr: ":9080", + StreamLargeBodies: 1024 * 1024 * 5, + } + + p, err := proxy.NewProxy(opts) + if err != nil { + log.Fatal(err) + } + + p.AddAddon(&AddHeader{}) + + log.Fatal(p.Start()) +}