Esempio n. 1
0
        /// <summary>
        /// Reads a token or token=(token|quoted-string) from the <paramref name="lexer"/>, convert it to a key value pair and advances the <paramref name="lexer"/>.
        /// </summary>
        /// <param name="lexer">The lexer to read from.</param>
        /// <returns>The converted key value pair.</returns>
        private static KeyValuePair<string, string> ReadKeyValuePair(ref HttpHeaderValueLexer lexer)
        {
            Debug.Assert(lexer.Type == HttpHeaderValueItemType.Token, "lexer.Type == HttpHeaderValueItemType.Token");

            string name = lexer.OriginalText;
            string value = null;
            lexer = lexer.ReadNext();
            if (lexer.Type == HttpHeaderValueItemType.ValueSeparator)
            {
                lexer = lexer.ReadNext();
                Debug.Assert(
                    lexer.Type == HttpHeaderValueItemType.Token || lexer.Type == HttpHeaderValueItemType.QuotedString,
                    "lexer.Type == HttpHeaderValueItemType.Token || lexer.Type == HttpHeaderValueItemType.QuotedString");

                value = lexer.OriginalText;
                lexer = lexer.ReadNext();
            }

            Debug.Assert(
                lexer.Type == HttpHeaderValueItemType.End || lexer.Type == HttpHeaderValueItemType.ElementSeparator || lexer.Type == HttpHeaderValueItemType.ParameterSeparator,
                "lexer.Type == HttpHeaderValueItemType.End || lexer.Type == HttpHeaderValueItemType.ElementSeparator || lexer.Type == HttpHeaderValueItemType.ParameterSeparator");

            return new KeyValuePair<string, string>(name, value);
        }
 /// <summary>
 /// Parses the current preference values to a dictionary of preference and value pairs.
 /// </summary>
 /// <returns>Returns a dictionary of preference and value pairs; null if the preference header has not been set.</returns>
 private HttpHeaderValue ParsePreferences()
 {
     string preferenceHeaderValue = this.message.GetHeader(this.preferenceHeaderName);
     HttpHeaderValueLexer preferenceHeaderLexer = HttpHeaderValueLexer.Create(this.preferenceHeaderName, preferenceHeaderValue);
     return preferenceHeaderLexer.ToHttpHeaderValue();
 }
Esempio n. 3
0
        /// <summary>
        /// Reads a <see cref="HttpHeaderValueElement"/> from <paramref name="lexer"/> and advances the <paramref name="lexer"/> forward.
        /// </summary>
        /// <param name="lexer">The lexer to read from.</param>
        /// <returns>The <see cref="HttpHeaderValueElement"/> that was read.</returns>
        private static HttpHeaderValueElement ReadHttpHeaderValueElement(ref HttpHeaderValueLexer lexer)
        {
            Debug.Assert(lexer.Type == HttpHeaderValueItemType.Token, "lexer.Type == HttpHeaderValueItemType.Token");

            List<KeyValuePair<string, string>> keyValuePairs = new List<KeyValuePair<string, string>> { ReadKeyValuePair(ref lexer) };
            while (lexer.Type == HttpHeaderValueItemType.ParameterSeparator)
            {
                lexer = lexer.ReadNext();
                keyValuePairs.Add(ReadKeyValuePair(ref lexer));
            }

            Debug.Assert(
                lexer.Type == HttpHeaderValueItemType.ElementSeparator || lexer.Type == HttpHeaderValueItemType.End,
                "lexer.Type == HttpHeaderValueItemType.ElementSeparator || lexer.Type == HttpHeaderValueItemType.End");
            return new HttpHeaderValueElement(keyValuePairs[0].Key, keyValuePairs[0].Value, keyValuePairs.Skip(1).ToArray());
        }