Ejemplo n.º 1
0
        private bool CheckRequestHeader(IEtaggable data, CacheRequestHeaders header)
        {
            var headerName = header == CacheRequestHeaders.IfMatch ? "If-Match" : "If-None-Match";

            var eTag = StringValues.Empty;

            var headerHasValue = _headers.TryGetValue(headerName, out eTag);

            var entityEtag = data.GetEtag(_hashAlgorithm);

            switch (header)
            {
            case CacheRequestHeaders.IfMatch:
                if (!headerHasValue)
                {
                    return(false);
                }

                return(eTag.Contains(entityEtag, StringComparer.OrdinalIgnoreCase));

            default:
                if (!headerHasValue)
                {
                    return(true);
                }
                return(!eTag.Contains(entityEtag, StringComparer.OrdinalIgnoreCase));
            }
        }
        public bool NoneMatch(IEtaggable entity)
        {
            if (!_headers.TryGetValue("If-None-Match", out var etags))
            {
                return(true);
            }

            var entityEtag = entity.GetEtag();

            if (string.IsNullOrEmpty(entityEtag))
            {
                return(true);
            }

            if (!entityEtag.Contains('"'))
            {
                entityEtag = $"\"{entityEtag}\"";
            }

            return(!etags.Contains(entityEtag));
        }