func (tb *Recorder) ObserveRequest(req Request) {
	tb.mutex.Lock()
	defer tb.mutex.Unlock()
	if len(tb.Header) != 0 {
		netutils.CopyHeaders(req.GetHttpRequest().Header, tb.Header)
	}
	tb.ProcessedRequests = append(tb.ProcessedRequests, req)
}
func (tb *Recorder) ProcessRequest(req Request) (*http.Response, error) {
	tb.mutex.Lock()
	defer tb.mutex.Unlock()

	if len(tb.Header) != 0 {
		netutils.CopyHeaders(req.GetHttpRequest().Header, tb.Header)
	}
	tb.ProcessedRequests = append(tb.ProcessedRequests, req)
	return tb.Response, tb.Error
}
func (tb *Recorder) ObserveResponse(req Request, a Attempt) {
	tb.mutex.Lock()
	defer tb.mutex.Unlock()
	if len(tb.Header) != 0 {
		netutils.CopyHeaders(req.GetHttpRequest().Header, tb.Header)
	}
	tb.ProcessedResponses = append(tb.ProcessedResponses, struct {
		R Request
		A Attempt
	}{R: req, A: a})
}
Exemple #4
0
func Post(c *check.C, requestUrl string, header http.Header, body url.Values) (*http.Response, []byte) {
	request, _ := http.NewRequest("POST", requestUrl, strings.NewReader(body.Encode()))
	netutils.CopyHeaders(request.Header, header)
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	request.Close = true
	response, err := http.DefaultClient.Do(request)
	if err != nil {
		c.Fatalf("Post: %v", err)
	}

	bodyBytes, err := ioutil.ReadAll(response.Body)
	if err != nil {
		c.Fatalf("Post body failed: %v", err)
	}
	return response, bodyBytes
}
Exemple #5
0
func Get(c *check.C, requestUrl string, header http.Header, body string) (*http.Response, []byte) {
	request, _ := http.NewRequest("GET", requestUrl, strings.NewReader(body))
	netutils.CopyHeaders(request.Header, header)
	request.Close = true
	// the HTTP lib treats Host as a special header.  it only respects the value on req.Host, and ignores
	// values in req.Headers
	if header.Get("Host") != "" {
		request.Host = header.Get("Host")
	}
	response, err := http.DefaultClient.Do(request)
	if err != nil {
		c.Fatalf("Get: %v", err)
	}

	bodyBytes, err := ioutil.ReadAll(response.Body)
	if err != nil {
		c.Fatalf("Get body failed: %v", err)
	}
	return response, bodyBytes
}