예제 #1
0
파일: proxy.go 프로젝트: FoxComm/vulcan
// Round trips the request to the selected location and writes back the response
func (p *Proxy) proxyRequest(w http.ResponseWriter, r *http.Request) error {

	// Create a unique request with sequential ids that will be passed to all interfaces.
	req := request.NewBaseRequest(r, atomic.AddInt64(&p.lastRequestId, 1), nil)
	location, err := p.router.Route(req)
	if err != nil {
		return err
	}

	// Router could not find a matching location, we can do nothing else.
	if location == nil {
		log.Errorf("%s failed to route", req)
		return errors.FromStatus(http.StatusBadGateway)
	}

	response, err := location.RoundTrip(req)
	if response != nil {
		netutils.CopyHeaders(w.Header(), response.Header)
		w.WriteHeader(response.StatusCode)
		io.Copy(w, response.Body)
		response.Body.Close()
		return nil
	} else {
		return err
	}
}
예제 #2
0
func makeRequest(o O) *request.BaseRequest {
	req := request.NewBaseRequest(&http.Request{URL: &url.URL{}}, o.id, nil)
	if o.noAttempts {
		return req
	}
	req.SetUserData(cbreakerMetrics, o.stats)
	req.Attempts = []request.Attempt{
		&request.BaseAttempt{},
	}
	return req
}