Skip to content

Instantly share code, notes, and snippets.

@unknwon
Last active March 10, 2022 09:16
Show Gist options
  • Save unknwon/00c34f8db5e5e8116a9da67ce2b62948 to your computer and use it in GitHub Desktop.
Save unknwon/00c34f8db5e5e8116a9da67ce2b62948 to your computer and use it in GitHub Desktop.
Transparent HTTP proxy server in Go
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
)
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