code: func (p *AuthProxy) Listen() error {
  	mux := bone.New()
  	proxy := &httputil.ReverseProxy{
  		Transport: p.t,
  		Director: func(r *http.Request) {
  			r.URL.Scheme = p.u.Scheme
  			r.URL.Host = p.u.Host
  			r.Host = p.u.Host
  			r.URL.Path = r.URL.Path[6:]
  
  			if p.sess.HasToken() {
  				tok := string(p.sess.Token())
  				r.Header["Authorization"] = []string{"Bearer " + tok}
  			}
  
  			r.Header["User-Agent"] = []string{"Torus-Daemon/" + p.c.Version}
  			r.Header["X-Registry-Version"] = []string{p.c.APIVersion}
  		},
  	}
  
  	go p.o.Start()
  
  	mux.HandleFunc("/proxy/", proxyCanceler(proxy))
  	mux.SubRoute("/v1", routes.NewRouteMux(p.c, p.sess, p.db, p.t, p.o, p.client, p.logic, p.updates))
  
  	h := httpdown.HTTP{}
  	p.s = h.Serve(&http.Server{Handler: requestIDHandler(loggingHandler(mux))}, p.l)
  
  	return p.s.Wait()
  }
docs: // Listen starts the main loop of the AuthProxy. It returns on error, or when
  // the AuthProxy is closed.