示例#1
0
 void Parse4(int nameStart, int valueStart, int valueEnd)
 {
     if (CharUtil.RegionMatchesIgnoreCase(_header, nameStart, CookieHeaderNames.Path, 0, 4))
     {
         _path = ComputeValue(valueStart, valueEnd);
     }
 }
 void Parse8(int nameStart)
 {
     if (CharUtil.RegionMatchesIgnoreCase(this.header, nameStart, CookieHeaderNames.HttpOnly, 0, 8))
     {
         this.httpOnly = true;
     }
 }
示例#3
0
 void Parse8(int nameStart, int valueStart, int valueEnd)
 {
     if (CharUtil.RegionMatchesIgnoreCase(_header, nameStart, CookieHeaderNames.HttpOnly, 0, 8))
     {
         _httpOnly = true;
     }
     else if (CharUtil.RegionMatchesIgnoreCase(_header, nameStart, CookieHeaderNames.SameSite, 0, 8))
     {
         _sameSite = (SameSite)Enum.Parse(typeof(SameSite), ComputeValue(valueStart, valueEnd), true);
     }
 }
示例#4
0
 void Parse6(int nameStart, int valueStart, int valueEnd)
 {
     if (CharUtil.RegionMatchesIgnoreCase(_header, nameStart, CookieHeaderNames.Domain, 0, 5))
     {
         _domain = ComputeValue(valueStart, valueEnd);
     }
     else if (CharUtil.RegionMatchesIgnoreCase(_header, nameStart, CookieHeaderNames.Secure, 0, 5))
     {
         _secure = true;
     }
 }
示例#5
0
 void Parse7(int nameStart, int valueStart, int valueEnd)
 {
     if (CharUtil.RegionMatchesIgnoreCase(_header, nameStart, CookieHeaderNames.Expires, 0, 7))
     {
         _expiresStart = valueStart;
         _expiresEnd   = valueEnd;
     }
     else if (CharUtil.RegionMatchesIgnoreCase(_header, nameStart, CookieHeaderNames.MaxAge, 0, 7))
     {
         SetMaxAge(ComputeValue(valueStart, valueEnd));
     }
 }
示例#6
0
        private void Decode(string header, ICollection <ICookie> cookies)
        {
            int headerLen = header.Length;
            int i         = 0;

            bool rfc2965Style = false;

            if (CharUtil.RegionMatchesIgnoreCase(header, 0, RFC2965Version, 0, RFC2965Version.Count))
            {
                // RFC 2965 style cookie, move to after version value
                i            = header.IndexOf(';') + 1;
                rfc2965Style = true;
            }

            // loop
            while (true)
            {
                // Skip spaces and separators.
                while (true)
                {
                    if (i == headerLen)
                    {
                        goto loop;
                    }
                    char c = header[i];
                    if (IsSpace(c))
                    {
                        i++;
                        continue;
                    }
                    break;
                }

                int nameBegin = i;
                int nameEnd;
                int valueBegin;
                int valueEnd;

                while (true)
                {
                    char curChar = header[i];
                    switch (curChar)
                    {
                    case HttpConstants.SemicolonChar:
                        // NAME; (no value till ';')
                        nameEnd    = i;
                        valueBegin = valueEnd = -1;
                        goto loop0;

                    case HttpConstants.EqualsSignChar:
                        // NAME=VALUE
                        nameEnd = i;
                        i++;
                        if (i == headerLen)
                        {
                            // NAME= (empty value, i.e. nothing after '=')
                            valueBegin = valueEnd = 0;
                            goto loop0;
                        }

                        valueBegin = i;
                        // NAME=VALUE;
                        int semiPos = header.IndexOf(';', i);
                        valueEnd = i = semiPos > 0 ? semiPos : headerLen;
                        goto loop0;

                    default:
                        i++;
                        break;
                    }

                    if (i == headerLen)
                    {
                        // NAME (no value till the end of string)
                        nameEnd    = headerLen;
                        valueBegin = valueEnd = -1;
                        break;
                    }
                }
loop0:
                if (rfc2965Style && (CharUtil.RegionMatches(header, nameBegin, RFC2965Path, 0, RFC2965Path.Count) ||
                                     CharUtil.RegionMatches(header, nameBegin, RFC2965Domain, 0, RFC2965Domain.Count) ||
                                     CharUtil.RegionMatches(header, nameBegin, RFC2965Port, 0, RFC2965Port.Count)))
                {
                    // skip obsolete RFC2965 fields
                    continue;
                }

                DefaultCookie cookie = InitCookie(header, nameBegin, nameEnd, valueBegin, valueEnd);
                if (cookie is object)
                {
                    cookies.Add(cookie);
                }
            }

loop:
            return;
        }
        public ISet <ICookie> Decode(string header)
        {
            Contract.Requires(header != null);

            int headerLen = header.Length;

            if (headerLen == 0)
            {
                return(Empty);
            }

            var cookies = new SortedSet <ICookie>();

            int i = 0;

            bool rfc2965Style = false;

            if (CharUtil.RegionMatchesIgnoreCase(header, 0, RFC2965Version, 0, RFC2965Version.Count))
            {
                // RFC 2965 style cookie, move to after version value
                i            = header.IndexOf(';') + 1;
                rfc2965Style = true;
            }

            // loop
            for (;;)
            {
                // Skip spaces and separators.
                for (;;)
                {
                    if (i == headerLen)
                    {
                        goto loop;
                    }
                    char c = header[i];
                    if (c == '\t' || c == '\n' || c == 0x0b || c == '\f' ||
                        c == '\r' || c == ' ' || c == ',' || c == ';')
                    {
                        i++;
                        continue;
                    }
                    break;
                }

                int nameBegin = i;
                int nameEnd;
                int valueBegin;
                int valueEnd;

                for (;;)
                {
                    char curChar = header[i];
                    if (curChar == ';')
                    {
                        // NAME; (no value till ';')
                        nameEnd    = i;
                        valueBegin = valueEnd = -1;
                        break;
                    }
                    else if (curChar == '=')
                    {
                        // NAME=VALUE
                        nameEnd = i;
                        i++;
                        if (i == headerLen)
                        {
                            // NAME= (empty value, i.e. nothing after '=')
                            valueBegin = valueEnd = 0;
                            break;
                        }

                        valueBegin = i;
                        // NAME=VALUE;
                        int semiPos = header.IndexOf(';', i);
                        valueEnd = i = semiPos > 0 ? semiPos : headerLen;
                        break;
                    }
                    else
                    {
                        i++;
                    }

                    if (i == headerLen)
                    {
                        // NAME (no value till the end of string)
                        nameEnd    = headerLen;
                        valueBegin = valueEnd = -1;
                        break;
                    }
                }

                if (rfc2965Style && (CharUtil.RegionMatches(header, nameBegin, RFC2965Path, 0, RFC2965Path.Count) ||
                                     CharUtil.RegionMatches(header, nameBegin, RFC2965Domain, 0, RFC2965Domain.Count) ||
                                     CharUtil.RegionMatches(header, nameBegin, RFC2965Port, 0, RFC2965Port.Count)))
                {
                    // skip obsolete RFC2965 fields
                    continue;
                }

                DefaultCookie cookie = this.InitCookie(header, nameBegin, nameEnd, valueBegin, valueEnd);
                if (cookie != null)
                {
                    cookies.Add(cookie);
                }
            }

loop:
            return(cookies);
        }
 public bool RegionMatchesIgnoreCase(int thisStart, ICharSequence seq, int start, int length) =>
 CharUtil.RegionMatchesIgnoreCase(this, thisStart, seq, start, length);