Represents an HTTP header value.
Exemple #1
0
        /// <summary>Tries to parse a given string as an <see cref="HeaderValue" />.</summary>
        /// <param name="value">String to be parsed.</param>
        /// <param name="headerValue">Resulting header value if parsing was successful; otherwise <b>null</b>.</param>
        /// <returns><b>true</b> if parsing was successful; otherwise <b>false</b>.</returns>
        public static bool TryParse(string value, out HeaderValue headerValue)
        {
            bool result = false;
            headerValue = null;
            try
            {
                headerValue = Parse(value);
                result = true;
            }
            catch
            {
            }

            return result;
        }
Exemple #2
0
        /// <summary>Tries to parse a given string as an <see cref="HeaderValue" />.</summary>
        /// <param name="value">String to be parsed.</param>
        /// <param name="headerValue">Resulting header value if parsing was successful; otherwise <b>null</b>.</param>
        /// <returns><b>true</b> if parsing was successful; otherwise <b>false</b>.</returns>
        public static bool TryParse(string value, out HeaderValue headerValue)
        {
            bool result = false;

            headerValue = null;
            try
            {
                headerValue = Parse(value);
                result      = true;
            }
            catch
            {
            }

            return(result);
        }
Exemple #3
0
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            if (!(obj is HeaderValue))
            {
                return(false);
            }

            if (ReferenceEquals(this, obj))
            {
                return(true);
            }

            HeaderValue value = (HeaderValue)obj;

            return(Value.Equals(value.Value) && (Parameters.SequenceEqual(value.Parameters)));
        }
Exemple #4
0
 private static void ParseSeparatorChar(char chr, ref bool isInString, ref bool isEscape, StringBuilder value, IList <HeaderValue> values)
 {
     if (isEscape)
     {
         isEscape = false;
         value.Append("\\" + chr);
     }
     else if (isInString)
     {
         value.Append(chr);
     }
     else
     {
         values.Add(HeaderValue.Parse(value.ToString().Trim()));
         value.Clear();
     }
 }
Exemple #5
0
        bool ICollection <KeyValuePair <string, string> > .Remove(KeyValuePair <string, string> item)
        {
            Header header = this[item.Key];

            if (header == null)
            {
                return(false);
            }

            HeaderValue value = header.Values.FirstOrDefault(valueItem => valueItem.Value == item.Value);

            if (value == null)
            {
                return(false);
            }

            header.Values.Remove(value);
            return(true);
        }
 public void Teardown()
 {
     _headerValue = null;
 }
 public void Setup()
 {
     _headerValue = (HeaderValue<int>)HeaderValue.ParseInternal("Content-Length", Value.ToString());
 }
 public void it_should_consider_same_instance_as_equal()
 {
     var value = new HeaderValue("test");
     value.Equals(value).Should().BeTrue();
 }