// returns true if the HTTP response contains a bearer challenge
6637
func hasBearerChallenge(resp *http.Response) bool {
	authHeader := resp.Header.Get(bearerChallengeHeader)
	if len(authHeader) == 0 || strings.Index(authHeader, bearer) < 0 {
		return false
	}
	return true
}
762951
func (h HTTPCodeRanges) Contains(statusCode int) bool {
	for _, block := range h {
		if statusCode >= block[0] && statusCode <= block[1] {
			return true
		}
	}
	return false
}
1132343
func canUseRetryAfterHeader(r *request.Request) bool {
	switch r.HTTPResponse.StatusCode {
	case 429:
	case 503:
	default:
		return false
	}

	return true
}
1191822
func ValidChallenge(name string) bool {
	switch name {
	case ChallengeTypeHTTP01,
		ChallengeTypeDNS01,
		ChallengeTypeTLSALPN01:
		return true
	default:
		return false
	}
}
1327450
func (i ifCond) True(r *http.Request) bool {
	if c, ok := ifConditions[i.op]; ok {
		a, b := i.a, i.b
		if r != nil {
			replacer := NewReplacer(r, nil, "")
			a = replacer.Replace(i.a)
			b = replacer.Replace(i.b)
		}
		return c(a, b)
	}
	return false
}
191388
func HTTPNetworkPolicyRuleLess(r1, r2 *cilium.HttpNetworkPolicyRule) bool {
	headers1, headers2 := r1.Headers, r2.Headers
	switch {
	case len(headers1) < len(headers2):
		return true
	case len(headers1) > len(headers2):
		return false
	}
	// Assuming that the slices are sorted.
	for idx := range headers1 {
		header1, header2 := headers1[idx], headers2[idx]
		switch {
		case HeaderMatcherLess(header1, header2):
			return true
		case HeaderMatcherLess(header2, header1):
			return false
		}
	}

	// Elements are equal.
	return false
}
381050
func (c *Connection) checkSubscribeHeaders(h Headers) error {
	if _, ok := h.Contains(HK_DESTINATION); !ok {
		return EREQDSTSUB
	}
	//
	am, ok := h.Contains(HK_ACK)
	//
	switch c.Protocol() {
	case SPL_10:
		if ok { // Client supplied ack header
			if !validAckModes10[am] {
				return ESBADAM
			}
		}
	case SPL_11:
		fallthrough
	case SPL_12:
		if ok { // Client supplied ack header
			if !(validAckModes10[am] || validAckModes1x[am]) {
				return ESBADAM
			}
		}
	default:
		log.Fatalf("Internal protocol level error:<%s>\n", c.Protocol())
	}
	return nil
}
783554
func (slc *HttpClient) CheckForHttpResponseErrorsSilently(data []byte) error {
	var decodedResponse map[string]interface{}
	parseErr := json.Unmarshal(data, &decodedResponse)
	if parseErr == nil {
		return slc.HasErrors(decodedResponse)
	}

	return nil
}
738842
func validHeaderAcceptJSON(header http.Header) bool {
	if v, found := header["Accept"]; found {
		for _, v := range v {
			if v == "application/json" || v == "*/*" || v == "*/json" || v == "application/*" {
				return true
			}
		}
		return false
	}
	return true
}
451966
func isContentTypeHtml(res *http.Response) bool {
	if res != nil {
		ct := res.Header.Get("Content-Type")
		return ct == "" || strings.Contains(ct, "text/html")
	}
	return false
}
331645
func VerifyHTTPHeader(r *http.Request) error {
	token := r.Header.Get(HeaderName)
	if len(token) == 0 {
		return trace.BadParameter("cannot retrieve CSRF token from HTTP header %q", HeaderName)
	}

	err := VerifyToken(token, r)
	if err != nil {
		return trace.Wrap(err)
	}

	return nil
}
1219978
func (r *RPCWrapper) CheckValidity(req *Request, secret string) bool {

	digest := hmac.New(sha256.New, []byte(secret))

	hash, err := payloadHash(req.Payload)
	if err != nil {
		return false
	}

	if _, err := digest.Write(hash); err != nil {
		return false
	}

	return hmac.Equal(req.HashAuth, digest.Sum(nil))
}
138667
func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) {
	HTTPBodyContains(a.t, handler, method, url, values, str)
}
1080376
func (m *testRPC) CheckValidity(req *Request, secret string) bool {
	if mock := m.currentMocks(nil); mock != nil && mock.DestroyRPCClientMock != nil {
		return mock.CheckValidityMock(req, secret)
	}
	return false
}
1083496
func (v *URLIsPresent) IsValid(errors *validate.Errors) {
	if v.Field == "http://" || v.Field == "https://" {
		if v.Message == "" {
			v.Message = fmt.Sprintf("%s url is empty", v.Name)
		}
		errors.Add(GenerateKey(v.Name), v.Message)
	}
	parsedUrl, err := url.ParseRequestURI(v.Field)
	if err != nil {
		if v.Message == "" {
			v.Message = fmt.Sprintf("%s does not match url format. Err: %s", v.Name,
				err)
		}
		errors.Add(GenerateKey(v.Name), v.Message)
	} else {
		if parsedUrl.Scheme != "" && parsedUrl.Scheme != "http" && parsedUrl.Scheme != "https" {
			if v.Message == "" {
				v.Message = fmt.Sprintf("%s invalid url scheme", v.Name)
			}
			errors.Add(GenerateKey(v.Name), v.Message)
		}
	}
}
1049290
func encodeResponseErr(w http.ResponseWriter, err interface{}) {
	enc := json.NewEncoder(w)

	rErr, ok := err.(*apitypes.Error)
	if ok {
		w.WriteHeader(rErr.StatusCode())
		enc.Encode(rErr)
	} else {
		w.WriteHeader(http.StatusInternalServerError)
		enc.Encode(&errorMsg{
			Type:  apitypes.InternalServerError,
			Error: []string{"Internal server error"},
		})
	}
}
703636
func (ra *RegistrationAuthorityImpl) authzValidChallengeEnabled(authz *core.Authorization) bool {
	for _, chall := range authz.Challenges {
		if chall.Status == core.StatusValid {
			return ra.PA.ChallengeTypeEnabled(chall.Type)
		}
	}
	return false
}