Skip to content

Commit 030f6f2

Browse files
committed
Rename to mitmproxy-go package
1 parent e01e7cc commit 030f6f2

20 files changed

Lines changed: 118 additions & 118 deletions

File tree

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# mitmpgo
1+
# mitmproxy-go
22

33
An easy-use and flexible Man-In-The-Middle (MITM) proxy library for Go that enables transparent interception and inspection of HTTP, HTTPS, HTTP/2, and WebSocket traffic.
44

@@ -22,7 +22,7 @@ An easy-use and flexible Man-In-The-Middle (MITM) proxy library for Go that enab
2222
## Installation
2323

2424
```bash
25-
go get github.com/josexy/mitmpgo
25+
go get github.com/josexy/mitmproxy-go
2626
```
2727

2828
## Quick Start
@@ -38,14 +38,14 @@ import (
3838
"log"
3939
"net/http"
4040

41-
"github.com/josexy/mitmpgo"
41+
"github.com/josexy/mitmproxy-go"
4242
)
4343

4444
func main() {
4545
// Create MITM proxy handler
46-
handler, err := mitmpgo.NewMitmProxyHandler(
47-
mitmpgo.WithCACertPath("certs/ca.crt"),
48-
mitmpgo.WithCAKeyPath("certs/ca.key"),
46+
handler, err := mitmproxy.NewMitmProxyHandler(
47+
mitmproxy.WithCACertPath("certs/ca.crt"),
48+
mitmproxy.WithCAKeyPath("certs/ca.key"),
4949
)
5050
if err != nil {
5151
log.Fatal(err)
@@ -60,7 +60,7 @@ func main() {
6060
### With HTTP Interceptor
6161

6262
```go
63-
httpInterceptor := func(ctx context.Context, req *http.Request, invoker mitmpgo.HTTPDelegatedInvoker) (*http.Response, error) {
63+
httpInterceptor := func(ctx context.Context, req *http.Request, invoker mitmproxy.HTTPDelegatedInvoker) (*http.Response, error) {
6464
// Log request details
6565
fmt.Printf("%s %s\n", req.Method, req.URL)
6666
fmt.Printf(" Host: %s\n", req.Host)
@@ -78,17 +78,17 @@ httpInterceptor := func(ctx context.Context, req *http.Request, invoker mitmpgo.
7878
return resp, nil
7979
}
8080

81-
handler, err := mitmpgo.NewMitmProxyHandler(
82-
mitmpgo.WithCACertPath("certs/ca.crt"),
83-
mitmpgo.WithCAKeyPath("certs/ca.key"),
84-
mitmpgo.WithHTTPInterceptor(httpInterceptor),
81+
handler, err := mitmproxy.NewMitmProxyHandler(
82+
mitmproxy.WithCACertPath("certs/ca.crt"),
83+
mitmproxy.WithCAKeyPath("certs/ca.key"),
84+
mitmproxy.WithHTTPInterceptor(httpInterceptor),
8585
)
8686
```
8787

8888
### With WebSocket Interceptor
8989

9090
```go
91-
websocketInterceptor := func(ctx context.Context, req *http.Request, rsp *http.Response, fw mitmpgo.WebsocketFramesWatcher) {
91+
websocketInterceptor := func(ctx context.Context, req *http.Request, rsp *http.Response, fw mitmproxy.WebsocketFramesWatcher) {
9292
// Log WebSocket messages
9393
log.Printf("WS url: %s", req.URL.String())
9494

@@ -104,20 +104,20 @@ websocketInterceptor := func(ctx context.Context, req *http.Request, rsp *http.R
104104
}
105105
}
106106

107-
handler, err := mitmpgo.NewMitmProxyHandler(
108-
mitmpgo.WithCACertPath("certs/ca.crt"),
109-
mitmpgo.WithCAKeyPath("certs/ca.key"),
110-
mitmpgo.WithWebsocketInterceptor(websocketInterceptor),
107+
handler, err := mitmproxy.NewMitmProxyHandler(
108+
mitmproxy.WithCACertPath("certs/ca.crt"),
109+
mitmproxy.WithCAKeyPath("certs/ca.key"),
110+
mitmproxy.WithWebsocketInterceptor(websocketInterceptor),
111111
)
112112
```
113113

114114
### SOCKS5 Proxy Mode
115115

116116
```go
117117
func main() {
118-
handler, err := mitmpgo.NewMitmProxyHandler(
119-
mitmpgo.WithCACertPath("certs/ca.crt"),
120-
mitmpgo.WithCAKeyPath("certs/ca.key"),
118+
handler, err := mitmproxy.NewMitmProxyHandler(
119+
mitmproxy.WithCACertPath("certs/ca.crt"),
120+
mitmproxy.WithCAKeyPath("certs/ca.key"),
121121
)
122122
if err != nil {
123123
log.Fatal(err)
@@ -152,44 +152,44 @@ func main() {
152152

153153
```go
154154
// Specify CA certificate and key for TLS interception
155-
mitmpgo.WithCACertPath("path/to/ca.crt")
156-
mitmpgo.WithCAKeyPath("path/to/ca.key")
155+
mitmproxy.WithCACertPath("path/to/ca.crt")
156+
mitmproxy.WithCAKeyPath("path/to/ca.key")
157157

158158
// Use an upstream proxy
159-
mitmpgo.WithProxy("http://127.0.0.1:8080")
159+
mitmproxy.WithProxy("http://127.0.0.1:8080")
160160

161161
// Disable upstream proxy
162-
mitmpgo.WithDisableProxy()
162+
mitmproxy.WithDisableProxy()
163163

164164
// Add custom root CA certificates
165-
mitmpgo.WithRootCAs("path/to/root-ca1.crt", "path/to/root-ca2.crt")
165+
mitmproxy.WithRootCAs("path/to/root-ca1.crt", "path/to/root-ca2.crt")
166166

167167
// Configure certificate cache pool
168-
mitmpgo.WithCertCachePool(2048, 30, 15)
168+
mitmproxy.WithCertCachePool(2048, 30, 15)
169169

170170
// Custom dialer with timeout
171-
mitmpgo.WithDialer(&net.Dialer{
171+
mitmproxy.WithDialer(&net.Dialer{
172172
Timeout: 30 * time.Second,
173173
})
174174

175175
// Maximum channel size of WebSocket frames
176-
mitmpgo.WithMaxWebsocketFramesPerForward(4096)
176+
mitmproxy.WithMaxWebsocketFramesPerForward(4096)
177177
```
178178

179179
### Interceptor Options
180180

181181
```go
182182
// Set HTTP interceptor
183-
mitmpgo.WithHTTPInterceptor(httpInterceptor)
183+
mitmproxy.WithHTTPInterceptor(httpInterceptor)
184184

185185
// Set WebSocket interceptor
186-
mitmpgo.WithWebsocketInterceptor(websocketInterceptor)
186+
mitmproxy.WithWebsocketInterceptor(websocketInterceptor)
187187

188188
// Chain multiple HTTP interceptors (executed in order)
189-
mitmpgo.WithChainHTTPInterceptor(interceptor1, interceptor2, interceptor3)
189+
mitmproxy.WithChainHTTPInterceptor(interceptor1, interceptor2, interceptor3)
190190

191191
// Set error handler
192-
mitmpgo.WithErrorHandler(func(ec mitmpgo.ErrorContext) {
192+
mitmproxy.WithErrorHandler(func(ec mitmproxy.ErrorContext) {
193193
log.Printf("Error: %v", ec.Error)
194194
})
195195
```
@@ -198,35 +198,35 @@ mitmpgo.WithErrorHandler(func(ec mitmpgo.ErrorContext) {
198198

199199
```go
200200
// Skip SSL verification when connecting to servers (not recommended for production)
201-
mitmpgo.WithSkipVerifySSLFromServer()
201+
mitmproxy.WithSkipVerifySSLFromServer()
202202

203203
// mTLS client-authentication
204-
mitmpgo.WithClientCert("example.com", mitmpgo.ClientCert{CertPath: "certs/client.crt", KeyPath: "certs/client.key" })
204+
mitmproxy.WithClientCert("example.com", mitmproxy.ClientCert{CertPath: "certs/client.crt", KeyPath: "certs/client.key" })
205205
```
206206

207207
### Protocol Options
208208

209209
```go
210210
// Disable HTTP/2 support (use HTTP/1.1 only)
211-
mitmpgo.WithDisableHTTP2()
211+
mitmproxy.WithDisableHTTP2()
212212
```
213213

214214
### Domain Filtering
215215

216216
```go
217217
// Only intercept specific hosts (supports wildcards)
218-
mitmpgo.WithIncludeHosts("api.example.com", "*.example.org", "example.net")
218+
mitmproxy.WithIncludeHosts("api.example.com", "*.example.org", "example.net")
219219

220220
// Exclude specific hosts from interception (supports wildcards)
221-
mitmpgo.WithExcludeHosts("*.cdn.com", "static.example.com")
221+
mitmproxy.WithExcludeHosts("*.cdn.com", "static.example.com")
222222
```
223223

224224
## Metadata Access
225225

226226
Interceptors can access metadata from the context:
227227

228228
```go
229-
httpInterceptor := func(ctx context.Context, req *http.Request, invoker mitmpgo.HTTPDelegatedInvoker) (*http.Response, error) {
229+
httpInterceptor := func(ctx context.Context, req *http.Request, invoker mitmproxy.HTTPDelegatedInvoker) (*http.Response, error) {
230230
// Extract metadata from context
231231
mdCtx, _ := metadata.FromContext(ctx)
232232
md := mdCtx.MD()

bufconn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package mitmpgo
1+
package mitmproxy
22

33
import (
44
"bufio"
55
"io"
66
"net"
77

8-
"github.com/josexy/mitmpgo/buf"
8+
"github.com/josexy/mitmproxy-go/buf"
99
"github.com/josexy/websocket"
1010
)
1111

domain_tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mitmpgo
1+
package mitmproxy
22

33
import (
44
"strings"

domain_tree_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mitmpgo
1+
package mitmproxy
22

33
import (
44
"testing"

examples/chain-interceptors/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"net/http"
99
"os"
1010

11-
"github.com/josexy/mitmpgo"
11+
"github.com/josexy/mitmproxy-go"
1212
)
1313

1414
func main() {
@@ -23,10 +23,10 @@ func main() {
2323
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
2424
slog.SetDefault(logger)
2525

26-
handler, err := mitmpgo.NewMitmProxyHandler(
27-
mitmpgo.WithCACertPath(caCertPath),
28-
mitmpgo.WithCAKeyPath(caKeyPath),
29-
mitmpgo.WithChainHTTPInterceptor(httpInterceptor1, httpInterceptor2, httpInterceptor3),
26+
handler, err := mitmproxy.NewMitmProxyHandler(
27+
mitmproxy.WithCACertPath(caCertPath),
28+
mitmproxy.WithCAKeyPath(caKeyPath),
29+
mitmproxy.WithChainHTTPInterceptor(httpInterceptor1, httpInterceptor2, httpInterceptor3),
3030
)
3131
if err != nil {
3232
panic(err)
@@ -37,7 +37,7 @@ func main() {
3737
http.ListenAndServe(fmt.Sprintf("%s:%d", "127.0.0.1", port), handler)
3838
}
3939

40-
func httpInterceptor1(ctx context.Context, req *http.Request, invoker mitmpgo.HTTPDelegatedInvoker) (*http.Response, error) {
40+
func httpInterceptor1(ctx context.Context, req *http.Request, invoker mitmproxy.HTTPDelegatedInvoker) (*http.Response, error) {
4141
slog.Debug("httpInterceptor1 before", slog.String("host", req.Host), slog.String("method", req.Method), slog.String("url", req.URL.String()))
4242
rsp, err := invoker.Invoke(req)
4343
if err != nil {
@@ -47,7 +47,7 @@ func httpInterceptor1(ctx context.Context, req *http.Request, invoker mitmpgo.HT
4747
return rsp, err
4848
}
4949

50-
func httpInterceptor2(ctx context.Context, req *http.Request, invoker mitmpgo.HTTPDelegatedInvoker) (*http.Response, error) {
50+
func httpInterceptor2(ctx context.Context, req *http.Request, invoker mitmproxy.HTTPDelegatedInvoker) (*http.Response, error) {
5151
slog.Debug("httpInterceptor2 before", slog.String("host", req.Host), slog.String("method", req.Method), slog.String("url", req.URL.String()))
5252
rsp, err := invoker.Invoke(req)
5353
if err != nil {
@@ -57,7 +57,7 @@ func httpInterceptor2(ctx context.Context, req *http.Request, invoker mitmpgo.HT
5757
return rsp, err
5858
}
5959

60-
func httpInterceptor3(ctx context.Context, req *http.Request, invoker mitmpgo.HTTPDelegatedInvoker) (*http.Response, error) {
60+
func httpInterceptor3(ctx context.Context, req *http.Request, invoker mitmproxy.HTTPDelegatedInvoker) (*http.Response, error) {
6161
slog.Debug("httpInterceptor3 before", slog.String("host", req.Host), slog.String("method", req.Method), slog.String("url", req.URL.String()))
6262
rsp, err := invoker.Invoke(req)
6363
if err != nil {

examples/dumper/main.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"syscall"
2121
"time"
2222

23-
"github.com/josexy/mitmpgo"
24-
"github.com/josexy/mitmpgo/metadata"
23+
"github.com/josexy/mitmproxy-go"
24+
"github.com/josexy/mitmproxy-go/metadata"
2525
)
2626

2727
const CHUNK_SIZE = 512
@@ -124,7 +124,7 @@ func main() {
124124
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
125125
slog.SetDefault(logger)
126126

127-
errHandler := func(ec mitmpgo.ErrorContext) {
127+
errHandler := func(ec mitmproxy.ErrorContext) {
128128
slog.Error("mitm proxy error",
129129
slog.String("remote_addr", ec.RemoteAddr),
130130
slog.String("hostport", ec.Hostport),
@@ -134,26 +134,26 @@ func main() {
134134

135135
ctx, cancel := context.WithCancel(context.Background())
136136

137-
handler, err := mitmpgo.NewMitmProxyHandler(
138-
mitmpgo.WithCACertPath(caCertPath),
139-
mitmpgo.WithCAKeyPath(caKeyPath),
140-
mitmpgo.WithHTTPInterceptor(httpInterceptor),
141-
mitmpgo.WithWebsocketInterceptor(websocketInterceptor),
142-
mitmpgo.WithErrorHandler(errHandler),
143-
mitmpgo.WithStreamBaseContext(ctx),
144-
// mitmpgo.WithClientCert("127.0.0.1", mitmpgo.ClientCert{
137+
handler, err := mitmproxy.NewMitmProxyHandler(
138+
mitmproxy.WithCACertPath(caCertPath),
139+
mitmproxy.WithCAKeyPath(caKeyPath),
140+
mitmproxy.WithHTTPInterceptor(httpInterceptor),
141+
mitmproxy.WithWebsocketInterceptor(websocketInterceptor),
142+
mitmproxy.WithErrorHandler(errHandler),
143+
mitmproxy.WithStreamBaseContext(ctx),
144+
// mitmproxy.WithClientCert("127.0.0.1", mitmproxy.ClientCert{
145145
// CertPath: "certs/client.crt",
146146
// KeyPath: "certs/client.key",
147147
// }),
148-
// mitmpgo.WithRootCAs("certs/ca.crt"),
149-
// mitmpgo.WithIncludeHosts("ifconfig.co", "*.example.com", "example.com", "*.bilibili.com"),
150-
// mitmpgo.WithIncludeHosts("api.bilibili.com"),
151-
// mitmpgo.WithExcludeHosts("www.baidu.com"),
152-
// mitmpgo.WithProxy("http://127.0.0.1:7900"),
153-
// mitmpgo.WithDisableProxy(),
154-
// mitmpgo.WithDisableHTTP2(),
155-
// mitmpgo.WithSkipVerifySSLFromServer(),
156-
// mitmpgo.WithMaxWebsocketFramesPerForward(4096),
148+
// mitmproxy.WithRootCAs("certs/ca.crt"),
149+
// mitmproxy.WithIncludeHosts("ifconfig.co", "*.example.com", "example.com", "*.bilibili.com"),
150+
// mitmproxy.WithIncludeHosts("api.bilibili.com"),
151+
// mitmproxy.WithExcludeHosts("www.baidu.com"),
152+
// mitmproxy.WithProxy("http://127.0.0.1:7900"),
153+
// mitmproxy.WithDisableProxy(),
154+
// mitmproxy.WithDisableHTTP2(),
155+
// mitmproxy.WithSkipVerifySSLFromServer(),
156+
// mitmproxy.WithMaxWebsocketFramesPerForward(4096),
157157
)
158158
if err != nil {
159159
panic(err)
@@ -206,7 +206,7 @@ func main() {
206206
time.Sleep(time.Millisecond * 500)
207207
}
208208

209-
func httpInterceptor(ctx context.Context, req *http.Request, invoker mitmpgo.HTTPDelegatedInvoker) (*http.Response, error) {
209+
func httpInterceptor(ctx context.Context, req *http.Request, invoker mitmproxy.HTTPDelegatedInvoker) (*http.Response, error) {
210210
_md, _ := metadata.FromContext(ctx)
211211
md := _md.MD()
212212
slog.Debug("request",
@@ -267,7 +267,7 @@ func httpInterceptor(ctx context.Context, req *http.Request, invoker mitmpgo.HTT
267267
return rsp, err
268268
}
269269

270-
func websocketInterceptor(ctx context.Context, req *http.Request, rsp *http.Response, fw mitmpgo.WebsocketFramesWatcher) {
270+
func websocketInterceptor(ctx context.Context, req *http.Request, rsp *http.Response, fw mitmproxy.WebsocketFramesWatcher) {
271271
_md, _ := metadata.FromContext(ctx)
272272
md := _md.MD()
273273
slog.Debug("request",

examples/helloworld/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"os/signal"
1111
"syscall"
1212

13-
"github.com/josexy/mitmpgo"
13+
"github.com/josexy/mitmproxy-go"
1414
)
1515

1616
func main() {
@@ -25,7 +25,7 @@ func main() {
2525
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
2626
slog.SetDefault(logger)
2727

28-
httpInterceptor := func(ctx context.Context, req *http.Request, invoker mitmpgo.HTTPDelegatedInvoker) (*http.Response, error) {
28+
httpInterceptor := func(ctx context.Context, req *http.Request, invoker mitmproxy.HTTPDelegatedInvoker) (*http.Response, error) {
2929
slog.Debug("request", slog.String("host", req.Host), slog.String("method", req.Method), slog.String("url", req.URL.String()))
3030

3131
rsp, err := invoker.Invoke(req)
@@ -37,10 +37,10 @@ func main() {
3737
return rsp, err
3838
}
3939

40-
handler, err := mitmpgo.NewMitmProxyHandler(
41-
mitmpgo.WithCACertPath(caCertPath),
42-
mitmpgo.WithCAKeyPath(caKeyPath),
43-
mitmpgo.WithHTTPInterceptor(httpInterceptor),
40+
handler, err := mitmproxy.NewMitmProxyHandler(
41+
mitmproxy.WithCACertPath(caCertPath),
42+
mitmproxy.WithCAKeyPath(caKeyPath),
43+
mitmproxy.WithHTTPInterceptor(httpInterceptor),
4444
)
4545
if err != nil {
4646
panic(err)

0 commit comments

Comments
 (0)