service/endpoint.go
func (c *endpointClient) Proxy(path string, evt *event.Event, requestID string, w http.ResponseWriter, r *http.Request) error {
	rawurl := strings.TrimRight(c.endpoint, "/") + "/" + strings.Trim(path, "/")
	url, err := url.Parse(rawurl)
	if err != nil {
		log.Errorf("Got error while creating service proxy url %s: %s", rawurl, err)
		return err
	}
	director := func(req *http.Request) {
		if evt != nil {
			req.Header.Set("X-Tsuru-User", evt.Owner.Name)
			req.Header.Set("X-Tsuru-Eventid", evt.UniqueID.Hex())
		}
		requestIDHeader, err := config.GetString("request-id-header")
		if err == nil && requestID != "" && requestIDHeader != "" {
			req.Header.Set(requestIDHeader, requestID)
		}
		req.SetBasicAuth(c.username, c.password)
		req.Host = url.Host
		req.URL = url
	}
	proxy := &httputil.ReverseProxy{Director: director}
	proxy.ServeHTTP(w, r)
	return nil
}
func (c *endpointClient) Proxy(path string, evt *event.Event, requestID string, w http.ResponseWriter, r *http.Request) error {
	rawurl := strings.TrimRight(c.endpoint, "/") + "/" + strings.Trim(path, "/")
	url, err := url.Parse(rawurl)
	if err != nil {
		log.Errorf("Got error while creating service proxy url %s: %s", rawurl, err)
		return err
	}
	director := func(req *http.Request) {
		if evt != nil {
			req.Header.Set("X-Tsuru-User", evt.Owner.Name)
			req.Header.Set("X-Tsuru-Eventid", evt.UniqueID.Hex())
		}
		requestIDHeader, err := config.GetString("request-id-header")
		if err == nil && requestID != "" && requestIDHeader != "" {
			req.Header.Set(requestIDHeader, requestID)
		}
		req.SetBasicAuth(c.username, c.password)
		req.Host = url.Host
		req.URL = url
	}
	proxy := &httputil.ReverseProxy{Director: director}
	proxy.ServeHTTP(w, r)
	return nil
}
// Proxy is a proxy between tsuru and the service.
// This method allow customized service methods.