Exemplo n.º 1
0
        public static void Parse(string value, out string scheme, out Collection <string> parameters)
        {
            var space = value.IndexOf(' ');

            scheme = value.Substring(0, space).Trim();
            var remaining = value.Substring(space + 1).Trim();

            parameters = HeaderStore.ParseMultiValue(remaining, ',');
        }
Exemplo n.º 2
0
        static Collection <string> LoadHeaders(string s)
        {
            s = s.Substring(s.IndexOf('=') + 1).Trim();
            if (s.StartsWithInvariant("\""))
            {
                s = s.Substring(1).Trim();
            }
            if (s.EndsWithInvariant("\""))
            {
                s = s.Substring(0, s.Length - 1);
            }

            return(HeaderStore.ParseMultiValue(s, ','));
        }
        public static Cookie Parse(string value)
        {
            var cookie = new Cookie();

            foreach (var pair in HeaderStore.ParseMultiValue(value, ';'))
            {
                var eq = pair.IndexOf('=');
                if (eq == -1)
                {
                    cookie.Add(pair, Cookie.AttributeOnly);
                    continue;
                }

                cookie.Add(pair.Substring(0, eq).Trim(), pair.Substring(eq + 1).Trim());
            }

            return(cookie);
        }
Exemplo n.º 4
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);
        }