Ejemplo n.º 1
0
        public void CacheMatch(string value)
        {
            var headValues = new HeaderValues<EntityTag>();
            headValues.AddString("\"" + value + "\"");
            Client.DefaultHeaders.IfNoneMatch = headValues;

            if (Client.DefaultHeaders.CacheControl != null) return;

            var cc = new CacheControl { MaxAge = new TimeSpan(0) };

            Client.DefaultHeaders.CacheControl = cc;
        }
        public static CacheControl Parse(string headerValue)
        {
            var c = new CacheControl();
            foreach (var d in HeaderStore.ParseMultiValue(headerValue, ','))
            {
                var directive = d.ToUpper(CultureInfo.InvariantCulture);
                switch (directive)
                {
                    case "NO-CACHE":
                        c.NoCache = true;
                        continue;
                    case "NO-STORE":
                        c.NoStore = true;
                        continue;
                    case "MAX-STALE":
                        c.MaxStale = true;
                        c.MaxStaleLimit = null;
                        continue;
                    case "NO-TRANSFORM":
                        c.NoTransform = true;
                        continue;
                    case "ONLY-IF-CACHED":
                        c.OnlyIfCached = true;
                        continue;
                    case "PUBLIC":
                        c.Public = true;
                        continue;
                    case "PRIVATE":
                        c.Private = true;
                        continue;
                    case "MUST-REVALIDATE":
                        c.MustRevalidate = true;
                        continue;
                    case "PROXY-REVALIDATE":
                        c.ProxyRevalidate = true;
                        continue;
                }

                if (directive.StartsWithInvariant("no-cache"))
                {
                    c.noCacheHeaders = LoadHeaders(d);
                    c.NoCache = true;
                    continue;
                }

                if (directive.StartsWithInvariant("max-age"))
                {
                    c.MaxAge = GetDeltaSeconds(directive);
                    continue;
                }

                if (directive.StartsWithInvariant("max-stale"))
                {
                    c.MaxStaleLimit = GetDeltaSeconds(directive);
                    c.MaxStale = true;
                    continue;
                }

                if (directive.StartsWithInvariant("min-fresh"))
                {
                    c.MinFresh = GetDeltaSeconds(directive);
                    continue;
                }

                if (directive.StartsWithInvariant("private"))
                {
                    c.privateHeaders = LoadHeaders(d);
                    c.Private = true;
                    continue;
                }

                if (directive.StartsWithInvariant("s-maxage"))
                {
                    c.SharedMaxAge = GetDeltaSeconds(directive);
                    continue;
                }

                c.Extensions.Add(d);
            }
            return c;
        }
Ejemplo n.º 3
0
        public static CacheControl Parse(string headerValue)
        {
            var c = new CacheControl();

            foreach (var d in HeaderStore.ParseMultiValue(headerValue, ','))
            {
                var directive = d.ToUpper(CultureInfo.InvariantCulture);
                switch (directive)
                {
                case "NO-CACHE":
                    c.NoCache = true;
                    continue;

                case "NO-STORE":
                    c.NoStore = true;
                    continue;

                case "MAX-STALE":
                    c.MaxStale      = true;
                    c.MaxStaleLimit = null;
                    continue;

                case "NO-TRANSFORM":
                    c.NoTransform = true;
                    continue;

                case "ONLY-IF-CACHED":
                    c.OnlyIfCached = true;
                    continue;

                case "PUBLIC":
                    c.Public = true;
                    continue;

                case "PRIVATE":
                    c.Private = true;
                    continue;

                case "MUST-REVALIDATE":
                    c.MustRevalidate = true;
                    continue;

                case "PROXY-REVALIDATE":
                    c.ProxyRevalidate = true;
                    continue;
                }

                if (directive.StartsWithInvariant("no-cache"))
                {
                    c.noCacheHeaders = LoadHeaders(d);
                    c.NoCache        = true;
                    continue;
                }

                if (directive.StartsWithInvariant("max-age"))
                {
                    c.MaxAge = GetDeltaSeconds(directive);
                    continue;
                }

                if (directive.StartsWithInvariant("max-stale"))
                {
                    c.MaxStaleLimit = GetDeltaSeconds(directive);
                    c.MaxStale      = true;
                    continue;
                }

                if (directive.StartsWithInvariant("min-fresh"))
                {
                    c.MinFresh = GetDeltaSeconds(directive);
                    continue;
                }

                if (directive.StartsWithInvariant("private"))
                {
                    c.privateHeaders = LoadHeaders(d);
                    c.Private        = true;
                    continue;
                }

                if (directive.StartsWithInvariant("s-maxage"))
                {
                    c.SharedMaxAge = GetDeltaSeconds(directive);
                    continue;
                }

                c.Extensions.Add(d);
            }
            return(c);
        }