Exemple #1
0
 private StringSegment SingleSegment(OwinResponse response, string header)
 {
     HeaderSegmentCollection.Enumerator cursor = new HeaderSegmentCollection(response.GetHeaderUnmodified(header)).GetEnumerator();
     if (cursor.MoveNext())
     {
         HeaderSegment segment = cursor.Current;
         if (cursor.MoveNext() == false)
         {
             return(segment.Data);
         }
     }
     return(new StringSegment());
 }
Exemple #2
0
        public static void DeleteCookie(OwinResponse response, string key)
        {
            Func <string, bool> predicate = value => value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase);

            var deleteCookies  = new[] { Uri.EscapeDataString(key) + "=; expires=Thu, 01-Jan-1970 00:00:00 GMT" };
            var existingValues = response.GetHeaderUnmodified("Set-Cookie");

            if (existingValues == null || existingValues.Length == 0)
            {
                response.SetHeaderUnmodified("Set-Cookie", deleteCookies);
            }
            else
            {
                response.SetHeaderUnmodified("Set-Cookie", existingValues.Where(value => !predicate(value)).Concat(deleteCookies).ToArray());
            }
        }
Exemple #3
0
        public static void DeleteCookie(OwinResponse response, string key, CookieOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var domainHasValue = !string.IsNullOrEmpty(options.Domain);
            var pathHasValue   = !string.IsNullOrEmpty(options.Path);

            Func <string, bool> rejectPredicate;

            if (domainHasValue)
            {
                rejectPredicate = value =>
                                  value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase) &&
                                  value.IndexOf("domain=" + options.Domain, StringComparison.OrdinalIgnoreCase) != -1;
            }
            else if (pathHasValue)
            {
                rejectPredicate = value =>
                                  value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase) &&
                                  value.IndexOf("path=" + options.Path, StringComparison.OrdinalIgnoreCase) != -1;
            }
            else
            {
                rejectPredicate = value => value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase);
            }
            var existingValues = response.GetHeaderUnmodified("Set-Cookie");

            if (existingValues != null)
            {
                response.SetHeaderUnmodified("Set-Cookie", existingValues.Where(value => !rejectPredicate(value)).ToArray());
            }

            AddCookie(response, key, string.Empty, new CookieOptions
            {
                Path    = options.Path,
                Domain  = options.Domain,
                Expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
            });
        }
    public static void DeleteCookie(OwinResponse response, string key)
    {
        Func<string, bool> predicate = value => value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase);

            var deleteCookies = new[] { Uri.EscapeDataString(key) + "=; expires=Thu, 01-Jan-1970 00:00:00 GMT" };
            var existingValues = response.GetHeaderUnmodified("Set-Cookie");
            if (existingValues == null || existingValues.Length == 0)
            {
                response.SetHeaderUnmodified("Set-Cookie", deleteCookies);
            }
            else
            {
                response.SetHeaderUnmodified("Set-Cookie", existingValues.Where(value => !predicate(value)).Concat(deleteCookies).ToArray());
            }
    }
    public static void DeleteCookie(OwinResponse response, string key, CookieOptions options)
    {
        if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            var domainHasValue = !string.IsNullOrEmpty(options.Domain);
            var pathHasValue = !string.IsNullOrEmpty(options.Path);

            Func<string, bool> rejectPredicate;
            if (domainHasValue)
            {
                rejectPredicate = value =>
                    value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase) &&
                        value.IndexOf("domain=" + options.Domain, StringComparison.OrdinalIgnoreCase) != -1;
            }
            else if (pathHasValue)
            {
                rejectPredicate = value =>
                    value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase) &&
                        value.IndexOf("path=" + options.Path, StringComparison.OrdinalIgnoreCase) != -1;
            }
            else
            {
                rejectPredicate = value => value.StartsWith(key + "=", StringComparison.OrdinalIgnoreCase);
            }
            var existingValues = response.GetHeaderUnmodified("Set-Cookie");
            if (existingValues != null)
            {
                response.SetHeaderUnmodified("Set-Cookie", existingValues.Where(value => !rejectPredicate(value)).ToArray());
            }

            AddCookie(response, key, string.Empty, new CookieOptions
            {
                Path = options.Path,
                Domain = options.Domain,
                Expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
            });
    }