Skip to content

Commit

Permalink
map remote todo
Browse files Browse the repository at this point in the history
  • Loading branch information
lqqyt2423 committed Mar 6, 2023
1 parent bdccdd5 commit d1cfe58
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions addon/mapremote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package addon

import (
"github.com/lqqyt2423/go-mitmproxy/proxy"
)

// Path map rule:
// 1. mapFrom.Path /hello and mapTo.Path /world
// /hello => /world
// 2. mapFrom.Path /hello/* and mapTo.Path /world
// /hello => /world
// /hello/abc => /world/abc

type mapFrom struct {
Protocol string
Host string
Path string
}

type mapTo struct {
Protocol string
Host string
Path string
}

type mapItem struct {
From *mapFrom
To *mapTo
PerserveHost bool
Enable bool
}

func (item *mapItem) match(req *proxy.Request) bool {
if !item.Enable {
return false
}
if item.From.Protocol != "" && item.From.Protocol != req.URL.Scheme {
return false
}
// todo
return false
}

func (item *mapItem) replace(req *proxy.Request) *proxy.Request {
// todo
return req
}

type MapRemote struct {
proxy.BaseAddon
Items []*mapItem
Enable bool
}

func (mr *MapRemote) Requestheaders(f *proxy.Flow) {
if !mr.Enable {
return
}
for _, item := range mr.Items {
if item.match(f.Request) {
f.Request = item.replace(f.Request)
return
}
}
}

0 comments on commit d1cfe58

Please sign in to comment.