Esempio n. 1
0
// handleNoBid method inspects the HTTP response metadata such as response status and headers to
// determine if there is a no-bid, and returns an error if so.
//
// NOTE: handleNoBid does not attempt to read the HTTP response body to determine if the body also
// signifies a no-bid.
func (c *Client) handleNoBid(r *http.Response) error {
	if r.StatusCode != http.StatusOK {
		c.logUnnecessaryBodyIfAny(r)
		return &nobid{status: r.StatusCode}
	}

	if err := openrtb.ValidateResponseHeaders(r); err != nil {
		return &nobid{err: err}
	}

	return nil
}
Esempio n. 2
0
func TestValidateResponseHeaders(t *testing.T) {
	tests := []struct {
		h   http.Header
		err error
	}{
		{http.Header{"Content-Type": []string{"application/json"}}, nil},
		{http.Header{"Content-Type": []string{"application/json; charset=utf-8"}}, nil},
		{http.Header{"Content-Type": []string{"text/json"}}, openrtb.ErrIncorrectHttpContentType},
	}

	for i, test := range tests {
		t.Logf("Testing %d...", i)
		r := &http.Response{
			Header: test.h,
		}

		if err := openrtb.ValidateResponseHeaders(r); err != test.err {
			t.Errorf("Expected error, %v instead of %v.", test.err, err)
		}
	}
}