public override Maybe <IHeaderDictionary> TryValidate(
            IHeaderDictionary headers,
            CacheContentValidators response)
        {
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (headers.ContainsKey(HeaderNames.IfModifiedSince))
            {
                var modDate = headers[HeaderNames.IfModifiedSince];
                var equal   = response.LastModified.Equals(DateTimeOffset.Parse(modDate));

                return(equal ?
                       Maybe <IHeaderDictionary> .Some(response.GetHeaders()):
                       Maybe <IHeaderDictionary> .None);
            }

            return(base.TryValidate(headers, response));
        }
Ejemplo n.º 2
0
        public virtual Maybe <IHeaderDictionary> TryValidate(
            IHeaderDictionary headers,
            CacheContentValidators response)
        {
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            return(nextValidator == null ? Maybe <IHeaderDictionary> .None : nextValidator.TryValidate(headers, response));
        }
        //TODO: this can probably be called from decorator on infrastructure layer
        public Task SetCacheControlResponseAsync(
            CacheControlKey key,
            CacheContentValidators response)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            var str = JsonSerializer.Serialize(response);

            return(distributedCache.SetStringAsync(key.Key, str));
        }
Ejemplo n.º 4
0
        public override Maybe <IHeaderDictionary> TryValidate(IHeaderDictionary headers, CacheContentValidators response)
        {
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }

            if (headers.ContainsKey(HeaderNames.IfNoneMatch))
            {
                var eTags     = headers[HeaderNames.IfNoneMatch].ToArray();
                var someEqual = eTags.Any(m =>
                                          m.Equals(response.ETag, StringComparison.InvariantCultureIgnoreCase));

                return(someEqual ?
                       Maybe <IHeaderDictionary> .Some(response.GetHeaders()) :
                       Maybe <IHeaderDictionary> .None);
            }

            return(base.TryValidate(headers, response));
        }