private static void ParseMultipleRawHeaderValues(
     HeaderDescriptor descriptor,
     HttpHeaders.HeaderStoreItemInfo info,
     List <string> rawValues)
 {
     if (descriptor.Parser == null)
     {
         foreach (string rawValue in rawValues)
         {
             if (!HttpHeaders.ContainsInvalidNewLine(rawValue, descriptor.Name))
             {
                 HttpHeaders.AddValue(info, (object)rawValue, HttpHeaders.StoreLocation.Parsed);
             }
         }
     }
     else
     {
         foreach (string rawValue in rawValues)
         {
             if (!HttpHeaders.TryParseAndAddRawHeaderValue(descriptor, info, rawValue, true) && NetEventSource.IsEnabled)
             {
                 NetEventSource.Log.HeadersInvalidValue(descriptor.Name, rawValue);
             }
         }
     }
 }
 internal void SetParsedValue(HeaderDescriptor descriptor, object value)
 {
     HttpHeaders.HeaderStoreItemInfo headerInfo = this.GetOrCreateHeaderInfo(descriptor, true);
     headerInfo.InvalidValue = (object)null;
     headerInfo.ParsedValue  = (object)null;
     headerInfo.RawValue     = (object)null;
     HttpHeaders.AddValue(headerInfo, value, HttpHeaders.StoreLocation.Parsed);
 }
 internal bool TryAddWithoutValidation(HeaderDescriptor descriptor, string value)
 {
     if (value == null)
     {
         value = string.Empty;
     }
     HttpHeaders.AddValue(this.GetOrCreateHeaderInfo(descriptor, false), (object)value, HttpHeaders.StoreLocation.Raw);
     return(true);
 }
 private static void CloneAndAddValue(
     HttpHeaders.HeaderStoreItemInfo destinationInfo,
     object source)
 {
     if (source is ICloneable cloneable)
     {
         HttpHeaders.AddValue(destinationInfo, cloneable.Clone(), HttpHeaders.StoreLocation.Parsed);
     }
     else
     {
         HttpHeaders.AddValue(destinationInfo, source, HttpHeaders.StoreLocation.Parsed);
     }
 }
 internal bool TryAddWithoutValidation(HeaderDescriptor descriptor, IEnumerable <string> values)
 {
     if (values == null)
     {
         throw new ArgumentNullException(nameof(values));
     }
     HttpHeaders.HeaderStoreItemInfo headerInfo = this.GetOrCreateHeaderInfo(descriptor, false);
     foreach (string str in values)
     {
         HttpHeaders.AddValue(headerInfo, (object)(str ?? string.Empty), HttpHeaders.StoreLocation.Raw);
     }
     return(true);
 }
 private void ParseAndAddValue(
     HeaderDescriptor descriptor,
     HttpHeaders.HeaderStoreItemInfo info,
     string value)
 {
     if (descriptor.Parser == null)
     {
         HttpHeaders.CheckInvalidNewLine(value);
         HttpHeaders.AddValue(info, (object)(value ?? string.Empty), HttpHeaders.StoreLocation.Parsed);
     }
     else
     {
         if (!info.CanAddValue(descriptor.Parser))
         {
             throw new FormatException(SR.Format((IFormatProvider)CultureInfo.InvariantCulture, SR.net_http_headers_single_value_header, (object)descriptor.Name));
         }
         int    index = 0;
         object obj1  = descriptor.Parser.ParseValue(value, info.ParsedValue, ref index);
         if (value == null || index == value.Length)
         {
             if (obj1 == null)
             {
                 return;
             }
             HttpHeaders.AddValue(info, obj1, HttpHeaders.StoreLocation.Parsed);
         }
         else
         {
             List <object> objectList = new List <object>();
             if (obj1 != null)
             {
                 objectList.Add(obj1);
             }
             while (index < value.Length)
             {
                 object obj2 = descriptor.Parser.ParseValue(value, info.ParsedValue, ref index);
                 if (obj2 != null)
                 {
                     objectList.Add(obj2);
                 }
             }
             foreach (object obj2 in objectList)
             {
                 HttpHeaders.AddValue(info, obj2, HttpHeaders.StoreLocation.Parsed);
             }
         }
     }
 }
        private static void ParseSingleRawHeaderValue(
            HeaderDescriptor descriptor,
            HttpHeaders.HeaderStoreItemInfo info)
        {
            string rawValue = info.RawValue as string;

            if (descriptor.Parser == null)
            {
                if (HttpHeaders.ContainsInvalidNewLine(rawValue, descriptor.Name))
                {
                    return;
                }
                HttpHeaders.AddValue(info, (object)rawValue, HttpHeaders.StoreLocation.Parsed);
            }
            else
            {
                if (HttpHeaders.TryParseAndAddRawHeaderValue(descriptor, info, rawValue, true) || !NetEventSource.IsEnabled)
                {
                    return;
                }
                NetEventSource.Log.HeadersInvalidValue(descriptor.Name, rawValue);
            }
        }
 public void ParseAdd(string input)
 {
     headers.AddValue(input, headerInfo, false);
 }
        private static bool TryParseAndAddRawHeaderValue(
            HeaderDescriptor descriptor,
            HttpHeaders.HeaderStoreItemInfo info,
            string value,
            bool addWhenInvalid)
        {
            if (!info.CanAddValue(descriptor.Parser))
            {
                if (addWhenInvalid)
                {
                    HttpHeaders.AddValue(info, (object)(value ?? string.Empty), HttpHeaders.StoreLocation.Invalid);
                }
                return(false);
            }
            int    index       = 0;
            object parsedValue = (object)null;

            if (descriptor.Parser.TryParseValue(value, info.ParsedValue, ref index, out parsedValue))
            {
                if (value == null || index == value.Length)
                {
                    if (parsedValue != null)
                    {
                        HttpHeaders.AddValue(info, parsedValue, HttpHeaders.StoreLocation.Parsed);
                    }
                    return(true);
                }
                List <object> objectList = new List <object>();
                if (parsedValue != null)
                {
                    objectList.Add(parsedValue);
                }
                while (index < value.Length)
                {
                    if (descriptor.Parser.TryParseValue(value, info.ParsedValue, ref index, out parsedValue))
                    {
                        if (parsedValue != null)
                        {
                            objectList.Add(parsedValue);
                        }
                    }
                    else
                    {
                        if (!HttpHeaders.ContainsInvalidNewLine(value, descriptor.Name) & addWhenInvalid)
                        {
                            HttpHeaders.AddValue(info, (object)value, HttpHeaders.StoreLocation.Invalid);
                        }
                        return(false);
                    }
                }
                foreach (object obj in objectList)
                {
                    HttpHeaders.AddValue(info, obj, HttpHeaders.StoreLocation.Parsed);
                }
                return(true);
            }
            if (!HttpHeaders.ContainsInvalidNewLine(value, descriptor.Name) & addWhenInvalid)
            {
                HttpHeaders.AddValue(info, (object)(value ?? string.Empty), HttpHeaders.StoreLocation.Invalid);
            }
            return(false);
        }
 internal void AddParsedValue(HeaderDescriptor descriptor, object value)
 {
     HttpHeaders.AddValue(this.GetOrCreateHeaderInfo(descriptor, true), value, HttpHeaders.StoreLocation.Parsed);
 }