GetExtension() публичный статический Метод

public static GetExtension ( string mimeType ) : string
mimeType string
Результат string
        public override async Task ExecuteAsync(IRequest req, IResponse res, object requestDto)
        {
            if (req.Verb != HttpMethods.Get && req.Verb != HttpMethods.Head)
            {
                return;
            }
            if (req.IsInProcessRequest())
            {
                return;
            }

            var feature = HostContext.GetPlugin <HttpCacheFeature>();

            if (feature == null)
            {
                throw new NotSupportedException(ErrorMessages.CacheFeatureMustBeEnabled.LocalizeFmt(req, "[CacheResponse]"));
            }
            if (feature.DisableCaching)
            {
                return;
            }

            var keyBase   = "res:" + req.RawUrl;
            var keySuffix = MimeTypes.GetExtension(req.ResponseContentType);

            var modifiers = "";

            if (req.ResponseContentType == MimeTypes.Json)
            {
                string jsonp = req.GetJsonpCallback();
                if (jsonp != null)
                {
                    modifiers = "jsonp:" + jsonp.SafeVarName();
                }
            }

            if (VaryByUser)
            {
                modifiers += (modifiers.Length > 0 ? "+" : "") + "user:" + req.GetSessionId();
            }

            if (VaryByRoles is { Length : > 0 })
Пример #2
0
 public static string GetCacheKeyForSerialized(string cacheKey, string mimeType, string modifiers)
 {
     return(cacheKey + MimeTypes.GetExtension(mimeType) + modifiers);
 }
Пример #3
0
        public override async Task ExecuteAsync(IRequest req, IResponse res, object requestDto)
        {
            if (req.Verb != HttpMethods.Get && req.Verb != HttpMethods.Head)
                return;
            if (req.IsInProcessRequest())
                return;

            var feature = HostContext.GetPlugin<HttpCacheFeature>();
            if (feature == null)
                throw new NotSupportedException(ErrorMessages.CacheFeatureMustBeEnabled.LocalizeFmt(req, "[CacheResponse]"));
            if (feature.DisableCaching)
                return;

            var keyBase = "res:" + req.RawUrl;
            var keySuffix = MimeTypes.GetExtension(req.ResponseContentType);

            var modifiers = "";
            if (req.ResponseContentType == MimeTypes.Json)
            {
                string jsonp = req.GetJsonpCallback();
                if (jsonp != null)
                    modifiers = "jsonp:" + jsonp.SafeVarName();
            }

            if (VaryByUser)
                modifiers += (modifiers.Length > 0 ? "+" : "") + "user:"******"+" : "") + "role:" + role;
                        }
                    }
                }
            }

            if (VaryByHeaders != null && VaryByHeaders.Length > 0)
            {
                foreach (var header in VaryByHeaders)
                {
                    var value = req.GetHeader(header);
                    if (!string.IsNullOrEmpty(value))
                    {
                        modifiers += (modifiers.Length > 0 ? "+" : "") + $"{header}:{value}";
                    }
                }
            }

            if (modifiers.Length > 0)
                keySuffix += "+" + modifiers;

            var cacheInfo = new CacheInfo
            {
                KeyBase = keyBase,
                KeyModifiers = keySuffix,
                ExpiresIn = Duration > 0 ? TimeSpan.FromSeconds(Duration) : (TimeSpan?)null,
                MaxAge = MaxAge >= 0 ? TimeSpan.FromSeconds(MaxAge) : (TimeSpan?)null,
                CacheControl = CacheControl,
                VaryByUser = VaryByUser,
                LocalCache = LocalCache,
                NoCompression = NoCompression,
            };

            if (await req.HandleValidCache(cacheInfo).ConfigAwait())
                return;

            req.Items[Keywords.CacheInfo] = cacheInfo;
        }
        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (req.Verb != HttpMethods.Get && req.Verb != HttpMethods.Head)
            {
                return;
            }

            var feature = HostContext.GetPlugin <HttpCacheFeature>();

            if (feature == null)
            {
                throw new NotSupportedException(ErrorMessages.CacheFeatureMustBeEnabled.Fmt("[CacheResponse]"));
            }

            var keyBase   = "res:" + req.RawUrl;
            var keySuffix = MimeTypes.GetExtension(req.ResponseContentType);

            var modifiers = "";

            if (req.ResponseContentType == MimeTypes.Json)
            {
                string jsonp = req.GetJsonpCallback();
                if (jsonp != null)
                {
                    modifiers = "jsonp:" + jsonp.SafeVarName();
                }
            }

            if (VaryByUser)
            {
                modifiers += (modifiers.Length > 0 ? "+" : "") + "user:"******"+" : "") + "role:" + role;
                        }
                    }
                }
            }

            if (modifiers.Length > 0)
            {
                keySuffix += "+" + modifiers;
            }

            var cacheInfo = new CacheInfo
            {
                KeyBase      = keyBase,
                KeyModifiers = keySuffix,
                ExpiresIn    = Duration > 0 ? TimeSpan.FromSeconds(Duration) : (TimeSpan?)null,
                MaxAge       = MaxAge >= 0 ? TimeSpan.FromSeconds(MaxAge) : (TimeSpan?)null,
                CacheControl = CacheControl,
                VaryByUser   = VaryByUser,
                LocalCache   = LocalCache,
            };

            if (req.HandleValidCache(cacheInfo))
            {
                return;
            }

            req.Items[Keywords.CacheInfo] = cacheInfo;
        }