Esempio n. 1
0
        protected override Tristate Modified(HttpContext context, Media media, MediaOptions options)
        {
            string header1 = context.Request.Headers[Helper.Constants.Properties.IfNoneMatchHeader];

            if (!string.IsNullOrEmpty(header1) && header1 != media.MediaData.MediaId)
            {
                return(Tristate.True);
            }
            string header2 = context.Request.Headers[Helper.Constants.Properties.IfModifiedSinceHeader];

            if (!string.IsNullOrEmpty(header2))
            {
                if (WebUtil.TryGetValueOfIfModifiedSinceHeader(context.Request, out DateTime ifModifiedSince))
                {
                    return(MainUtil.GetTristate(!CompareDatesWithRounding(ifModifiedSince, media.MediaData.Updated, new TimeSpan(0, 0, 1))));
                }
                Log.Warn(string.Format(Helper.Constants.Message.ModifiedWarnMessage, (object)header2), (object)typeof(MediaRequestHandler));
            }
            return(Tristate.Undefined);
        }
Esempio n. 2
0
        protected override Tristate Modified(HttpContext context, Sitecore.Resources.Media.Media media, MediaOptions options)
        {
            string str1 = context.Request.Headers["If-None-Match"];

            if (!string.IsNullOrEmpty(str1) && str1 != media.MediaData.MediaId)
            {
                return(Tristate.True);
            }
            string str2 = context.Request.Headers["If-Modified-Since"];

            if (!string.IsNullOrEmpty(str2))
            {
                DateTime result;
                if (DateTime.TryParse(str2.Split(';')[0].Replace(" UTC", " GMT"), out result))
                {
                    return(MainUtil.GetTristate(!this.CompareDatesWithRounding(result, media.MediaData.Updated, new TimeSpan(0, 0, 1))));
                }
                Log.Warn(string.Format("Can't parse header. The wrong value  - \"If-Modified-Since: {0}\" ", (object)str2), (object)typeof(MediaRequestHandler));
            }
            return(Tristate.Undefined);
        }
Esempio n. 3
0
        public override void Process(HttpRequestArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            if (!CDNSettings.Enabled)
            {
                return;
            }

            bool shouldFilter = (Sitecore.Context.Item != null || CDNManager.ShouldProcessRequest(args.Url.FilePathWithQueryString)) && // if an item is resolved (this is a page request) or file ext is listed in <processRequests>
                                !CDNManager.ShouldExcludeProcessRequest(args.Url.FilePathWithQueryString) &&                            // if the url is not on the excluded list
                                Sitecore.Context.Site != null &&                                                                        // and a site was resolved
                                Sitecore.Context.PageMode.IsNormal &&                                                                   // and the site is not in editing mode
                                !string.IsNullOrEmpty(CDNManager.GetCDNHostName());                                                     // and the current site is not in the excluded sites list

            // querystring cdn=1  to force replacement
            // querystring cdn=0  to force no replacement
            Tristate force = MainUtil.GetTristate(WebUtil.GetQueryString("cdn"), Tristate.Undefined);

            if (force == Tristate.False)
            {
                shouldFilter = false;
            }
            else if (force == Tristate.True)
            {
                shouldFilter = true;
            }

            if (shouldFilter)
            {
                var response = HttpContext.Current.Response;
                if (response != null)
                {
                    // replace the default response filter stream with our replacer filter
                    response.Filter = new MediaUrlFilter(response.Filter);
                }
            }
        }