예제 #1
0
파일: basic.go 프로젝트: BenPhegan/goproxy
// Basic returns a basic HTTP authentication handler for requests
//
// You probably want to use auth.ProxyBasic(proxy) to enable authentication for all proxy activities
func Basic(realm string, f func(user, passwd string) bool) goproxy.ReqHandler {
	return goproxy.FuncReqHandler(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
		if !auth(req, f) {
			return nil, BasicUnauthorized(req, realm)
		}
		return req, nil
	})
}
예제 #2
0
파일: main.go 프로젝트: rakoo/rproxy
func main() {
	proxy := goproxy.NewProxyHttpServer()

	rp := NewRProxy()
	proxy.OnRequest().Do(goproxy.FuncReqHandler(rp.addSignature))
	proxy.OnResponse().Do(goproxy.FuncRespHandler(rp.patch))

	http.Handle("/", proxy)
	log.Println("Starting listening on :2424")
	log.Fatal(http.ListenAndServe(":2424", nil))
}
예제 #3
0
파일: main.go 프로젝트: rakoo/rproxy
func main() {
	proxy := goproxy.NewProxyHttpServer()

	rp := NewRproxy()
	proxy.OnRequest().Do(goproxy.FuncReqHandler(rp.storeSig))
	proxy.OnResponse().Do(goproxy.FuncRespHandler(rp.delta))

	http.Handle("/", proxy)
	log.Println("Starting listening on :8080")
	log.Fatal(http.ListenAndServe(":8080", nil))
}
예제 #4
0
func Basic(realm string, f func(user, passwd string) bool) goproxy.ReqHandler {
	return goproxy.FuncReqHandler(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
		authheader := strings.SplitN(req.Header.Get(proxyAuthorizatonHeader), " ", 2)
		req.Header.Del(proxyAuthorizatonHeader)
		if len(authheader) != 2 || authheader[0] != "Basic" {
			return nil, BasicUnauthorized(req, realm)
		}
		userpassraw, err := base64.StdEncoding.DecodeString(authheader[1])
		if err != nil {
			return nil, BasicUnauthorized(req, realm)
		}
		userpass := strings.SplitN(string(userpassraw), ":", 2)
		if len(userpass) != 2 {
			return nil, BasicUnauthorized(req, realm)
		}
		if !f(userpass[0], userpass[1]) {
			return nil, BasicUnauthorized(req, realm)
		}
		return req, nil
	})
}