Exemple #1
0
// this is similar to httputil.NewSingleHostReverseProxy except it passes along basic auth
func NewSingleHostReverseProxy(target *url.URL, connectTimeout time.Duration, requestTimeout time.Duration) *httputil.ReverseProxy {
	director := func(req *http.Request) {
		req.URL.Scheme = target.Scheme
		req.URL.Host = target.Host
		if target.User != nil {
			passwd, _ := target.User.Password()
			req.SetBasicAuth(target.User.Username(), passwd)
		}
	}
	return &httputil.ReverseProxy{
		Director:  director,
		Transport: http_api.NewDeadlineTransport(connectTimeout, requestTimeout),
	}
}
Exemple #2
0
func (n *NSQAdmin) handleAdminActions() {
	for action := range n.notifications {
		content, err := json.Marshal(action)
		if err != nil {
			n.logf("ERROR: failed to serialize admin action - %s", err)
		}
		httpclient := &http.Client{Transport: http_api.NewDeadlineTransport(10 * time.Second)}
		n.logf("POSTing notification to %s", n.opts.NotificationHTTPEndpoint)
		resp, err := httpclient.Post(n.opts.NotificationHTTPEndpoint,
			"application/json", bytes.NewBuffer(content))
		if err != nil {
			n.logf("ERROR: failed to POST notification - %s", err)
		}
		resp.Body.Close()
	}
}
Exemple #3
0
func init() {
	httpclient = &http.Client{Transport: http_api.NewDeadlineTransport(*httpTimeout)}
	userAgent = fmt.Sprintf("nsq_to_http v%s", version.Binary)
}
Exemple #4
0
func init() {
	httpclient = &http.Client{Transport: http_api.NewDeadlineTransport(*httpConnectTimeout, *httpRequestTimeout), Timeout: *httpRequestTimeout}
	userAgent = fmt.Sprintf("nsq_to_http v%s", version.Binary)
}