Last active
March 10, 2022 09:16
-
-
Save unknwon/00c34f8db5e5e8116a9da67ce2b62948 to your computer and use it in GitHub Desktop.
Transparent HTTP proxy server in Go
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
module goproxy | |
go 1.17 | |
require ( | |
github.com/elazarl/goproxy v0.0.0-20220115173737-adb46da277ac | |
github.com/elazarl/goproxy/ext v0.0.0-20220115173737-adb46da277ac | |
) |
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
package main | |
import ( | |
"flag" | |
"log" | |
"net/http" | |
"github.com/elazarl/goproxy" | |
"github.com/elazarl/goproxy/ext/auth" | |
) | |
func main() { | |
addr := flag.String("addr", ":29100", "Listen address") | |
username := flag.String("username", "", "Username") | |
password := flag.String("password", "", "Password") | |
flag.Parse() | |
proxy := goproxy.NewProxyHttpServer() | |
proxy.Verbose = true | |
auth.ProxyBasic(proxy, "csi", func(u, p string) bool { | |
return u == *username && p == *password | |
}) | |
proxy.OnRequest() | |
log.Fatal(http.ListenAndServe(*addr, proxy)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment