(proxy *goproxy.ProxyHttpServer, realm string, basicFunc func(user, passwd string) bool, bearerFunc func(token string) bool)
| 193 | } |
| 194 | |
| 195 | func proxyBasicAndBearer(proxy *goproxy.ProxyHttpServer, realm string, basicFunc func(user, passwd string) bool, bearerFunc func(token string) bool) { |
| 196 | |
| 197 | proxy.OnRequest().Do(goproxy.FuncReqHandler(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) { |
| 198 | if strings.HasSuffix(req.URL.Host, ":443") { |
| 199 | return req, nil |
| 200 | } |
| 201 | err := authFromHeader(req, basicFunc, bearerFunc) |
| 202 | if err != nil { |
| 203 | return nil, unauthorizedError(req, realm, err.Error()) |
| 204 | } |
| 205 | return req, nil |
| 206 | })) |
| 207 | |
| 208 | proxy.OnRequest().HandleConnect(goproxy.FuncHttpsHandler(func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) { |
| 209 | err := authFromHeader(ctx.Req, basicFunc, bearerFunc) |
| 210 | if err != nil { |
| 211 | ctx.Resp = unauthorizedError(ctx.Req, realm, err.Error()) |
| 212 | return goproxy.RejectConnect, host |
| 213 | } |
| 214 | return goproxy.MitmConnect, host |
| 215 | })) |
| 216 | } |
| 217 | |
| 218 | func authFromHeader(req *http.Request, basicFunc func(user, passwd string) bool, bearerFunc func(token string) bool) error { |
| 219 | headerValue := req.Header.Get(ProxyAuthorizationHeader) |
no test coverage detected