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 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); }