示例#1
0
func runTest(test testRecord, j int, webaddr string, t *testing.T) {
	var response *http.Response
	var err os.Error
	defer func() { done <- j }()
	url := "http://" + webaddr + test.URL
	if response, _, err = http.Get(url); err != nil {
		t.Error(err)
	}
	if response.StatusCode != test.StatusCode {
		t.Error(j, webaddr, test.URL, "Response had wrong status code:", response.StatusCode)
	}
	if len(test.BodyPrefix) > 0 {
		prefix := make([]byte, len(test.BodyPrefix))
		if n, err := response.Body.Read(prefix); err == nil {
			p := string(prefix[0:n])
			if p != test.BodyPrefix {
				t.Error(j, webaddr, test.URL, "Bad body, expected prefix:", test.BodyPrefix, "got:", p)
			}
		} else {
			t.Error(j, webaddr, test.URL, "Error reading response.Body:", err)
		}
	}
	if test.Headers != nil {
		for _, hdr := range test.Headers {
			if v := response.GetHeader(hdr.Key); v != hdr.Val {
				t.Error(j, webaddr, test.URL, "Header value in response:", strconv.Quote(v), "did not match", strconv.Quote(hdr.Val))
			}
		}
	}
}
示例#2
0
文件: twitter.go 项目: nictuku/gomine
func rateLimitStats(resp *http.Response) {
	if resp == nil {
		return
	}
	curr := time.Seconds()
	reset, _ := strconv.Atoi64(resp.GetHeader("X-RateLimit-Reset"))
	remaining, _ := strconv.Atoi64(resp.GetHeader("X-RateLimit-Remaining"))
	if remaining < 1 && reset-curr > 0 {
		log.Printf("Twitter API limits exceeded. Sleeping for %d seconds.\n", reset-curr)
		time.Sleep((reset - curr) * 1e9)
	}
}