-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a error handler to ConnectAction
This allows the users to client handle connect errors related to certificates, useful, as in the example, when some clients are using certificate pinning to allow them to connect without mitm
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"net/http" | ||
"sync" | ||
|
||
"github.com/elazarl/goproxy" | ||
) | ||
|
||
func main() { | ||
verbose := flag.Bool("v", false, "should every proxy request be logged to stdout") | ||
addr := flag.String("addr", ":8080", "proxy listen address") | ||
flag.Parse() | ||
proxy := goproxy.NewProxyHttpServer() | ||
var mitmErrorHosts sync.Map | ||
proxy.OnRequest().HandleConnectFunc(func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) { | ||
_, exists := mitmErrorHosts.Load(host) | ||
if exists { | ||
return goproxy.OkConnect, host | ||
} | ||
|
||
return &goproxy.ConnectAction{Action: goproxy.ConnectMitm, TLSConfig: goproxy.MitmConnect.TLSConfig, MitmError: func(req *http.Request, ctx *goproxy.ProxyCtx, err error) { | ||
log.Printf("Adding host to mitm error: %s", host) | ||
mitmErrorHosts.Store(host, true) | ||
}}, host | ||
}) | ||
proxy.Verbose = *verbose | ||
log.Fatal(http.ListenAndServe(*addr, proxy)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters