Example #1
0
        private void ParseImplementation(string headerStr, ref int pos, bool isOptionIsAnOption)
        {
            // According to https://tools.ietf.org/html/rfc7234#section-5.2.1.1
            // Max-Age has a form "max-age=5", but some (imgur.com specifically) sends it as "max-age:5"
            string key = headerStr.Read(ref pos, (ch) => ch != ';' && ch != '=' && ch != ':' && ch != ',', true);

            this.Key = key;

            char?skippedChar = headerStr.Peek(pos - 1);
            bool isValue     = skippedChar == '=' || skippedChar == ':';
            bool isOption    = isOptionIsAnOption && skippedChar == ';';

            while ((skippedChar != null && isValue || isOption) && pos < headerStr.Length)
            {
                if (isValue)
                {
                    string value = headerStr.ReadPossibleQuotedText(ref pos);
                    this.Value = value;
                }
                else if (isOption)
                {
                    HeaderValue option = new HeaderValue();
                    option.ParseImplementation(headerStr, ref pos, false);

                    if (this.Options == null)
                    {
                        this.Options = new List <HeaderValue>();
                    }

                    this.Options.Add(option);
                }

                if (!isOptionIsAnOption)
                {
                    return;
                }

                skippedChar = headerStr.Peek(pos - 1);
                isValue     = skippedChar == '=';
                isOption    = isOptionIsAnOption && skippedChar == ';';
            }
        }
Example #2
0
        private void ParseImplementation(string headerStr, ref int pos, bool isOptionIsAnOption)
        {
            string key = headerStr.Read(ref pos, (ch) => ch != ';' && ch != '=' && ch != ',', true);

            this.Key = key;

            char?skippedChar = headerStr.Peek(pos - 1);
            bool isValue     = skippedChar == '=';
            bool isOption    = isOptionIsAnOption && skippedChar == ';';

            while (skippedChar != null && isValue || isOption)
            {
                if (isValue)
                {
                    string value = headerStr.ReadPossibleQuotedText(ref pos);
                    this.Value = value;
                }
                else if (isOption)
                {
                    HeaderValue option = new HeaderValue();
                    option.ParseImplementation(headerStr, ref pos, false);

                    if (this.Options == null)
                    {
                        this.Options = new List <HeaderValue>();
                    }

                    this.Options.Add(option);
                }

                if (!isOptionIsAnOption)
                {
                    return;
                }

                skippedChar = headerStr.Peek(pos - 1);
                isValue     = skippedChar == '=';
                isOption    = isOptionIsAnOption && skippedChar == ';';
            }
        }
        private void ParseImplementation(string headerStr, ref int pos, bool isOptionIsAnOption)
        {
            string key = headerStr.Read(ref pos, (ch) => ch != ';' && ch != '=' && ch != ',', true);
            this.Key = key;

            char? skippedChar = headerStr.Peek(pos - 1);
            bool isValue = skippedChar == '=';
            bool isOption = isOptionIsAnOption && skippedChar == ';';

            while (skippedChar != null && isValue || isOption)
            {

                if (isValue)
                {
                    string value = headerStr.ReadPossibleQuotedText(ref pos);
                    this.Value = value;
                }
                else if (isOption)
                {
                    HeaderValue option = new HeaderValue();
                    option.ParseImplementation(headerStr, ref pos, false);

                    if (this.Options == null)
                        this.Options = new List<HeaderValue>();

                    this.Options.Add(option);
                }

                if (!isOptionIsAnOption)
                    return;

                skippedChar = headerStr.Peek(pos - 1);
                isValue = skippedChar == '=';
                isOption = isOptionIsAnOption && skippedChar == ';';
            }
        }