// Handler returns a http handler for a Proxy
Handler returns a http handler for a Proxy
// Handler returns a http handler for a Proxy
func (p *Proxy) Handler() http.Handler {
	mux := http.NewServeMux()
	mux.HandleFunc("/favicon.ico", p.Favicon)
	mux.HandleFunc("/robots.txt", p.RobotsTxt)
	mux.HandleFunc("/.pomerium/sign_out", p.SignOut)
	mux.HandleFunc("/.pomerium/callback", p.OAuthCallback)
	mux.HandleFunc("/", p.Proxy)
	c := middleware.NewChain()
	c = c.Append(middleware.Healthcheck("/ping", version.UserAgent()))
	c = c.Append(middleware.NewHandler(log.Logger))
	c = c.Append(middleware.AccessHandler(func(r *http.Request, status, size int, duration time.Duration) {
		middleware.FromRequest(r).Debug().
			Str("method", r.Method).
			Str("url", r.URL.String()).
			Int("status", status).
			Int("size", size).
			Dur("duration", duration).
			Str("pomerium-user", r.Header.Get(HeaderUserID)).
			Str("pomerium-email", r.Header.Get(HeaderEmail)).
			Msg("proxy: request")
	}))
	c = c.Append(middleware.SetHeaders(p.headers))
	c = c.Append(middleware.ForwardedAddrHandler("fwd_ip"))
	c = c.Append(middleware.RemoteAddrHandler("ip"))
	c = c.Append(middleware.UserAgentHandler("user_agent"))
	c = c.Append(middleware.RefererHandler("referer"))
	c = c.Append(middleware.RequestIDHandler("req_id", "Request-Id"))
	c = c.Append(middleware.ValidateHost(func(host string) bool {
		_, ok := p.routeConfigs[host]
		return ok
	}))
	return c.Then(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		mux.ServeHTTP(w, r)
	}))
}
func ( p * Proxy ) Handler ( ) http . Handler { mux := http . NewServeMux ( ) mux . HandleFunc ( " " , p . Favicon ) mux . HandleFunc ( " " , p . RobotsTxt ) mux . HandleFunc ( " " , p . SignOut ) mux . HandleFunc ( " " , p . OAuthCallback ) mux . HandleFunc ( " " , p . Proxy ) c := middleware . NewChain ( ) c = c . Append ( middleware . Healthcheck ( " " , version . UserAgent ( ) ) ) c = c . Append ( middleware . NewHandler ( log . Logger ) ) c = c . Append ( middleware . AccessHandler ( func ( r * http . Request , status , size int , duration time . Duration ) { middleware . FromRequest ( r ) . Debug ( ) . Str ( " " , r . Method ) . Str ( " " , r . URL . String ( ) ) . Int ( " " , status ) . Int ( " " , size ) . Dur ( " " , duration ) . Str ( " " , r . Header . Get ( HeaderUserID ) ) . Str ( " " , r . Header . Get ( HeaderEmail ) ) . Msg ( " " ) } ) ) c = c . Append ( middleware . SetHeaders ( p . headers ) ) c = c . Append ( middleware . ForwardedAddrHandler ( " " ) ) c = c . Append ( middleware . RemoteAddrHandler ( " " ) ) c = c . Append ( middleware . UserAgentHandler ( " " ) ) c = c . Append ( middleware . RefererHandler ( " " ) ) c = c . Append ( middleware . RequestIDHandler ( " " , " " ) ) c = c . Append ( middleware . ValidateHost ( func ( host string ) bool { _ , ok := p . routeConfigs [ host ] return ok } ) ) return c . Then ( http . HandlerFunc ( func ( w http . ResponseWriter , r * http . Request ) { mux . ServeHTTP ( w , r ) } ) ) }
Handler returns a http handler for a Proxy
Handler returns a http handler for a Proxy
// routes // mux.HandleFunc("/.pomerium/refresh", p.Refresh) //todo(bdd): needs DoS protection before inclusion // middleware chain // serve the middleware and mux