bool AddInternal(string name, IEnumerable <string> values, HeaderInfo headerInfo, bool ignoreInvalid) { HeaderBucket bucket; headers.TryGetValue(name, out bucket); bool ok = true; foreach (var value in values) { bool first_entry = bucket == null; if (headerInfo != null) { object parsed_value; if (!headerInfo.TryParse(value, out parsed_value)) { if (ignoreInvalid) { ok = false; continue; } throw new FormatException(); } if (headerInfo.AllowsMany) { if (bucket == null) { bucket = new HeaderBucket(headerInfo.CreateCollection(this), headerInfo.CustomToString); } headerInfo.AddToCollection(bucket.Parsed, parsed_value); } else { if (bucket != null) { throw new FormatException(); } bucket = new HeaderBucket(parsed_value, headerInfo.CustomToString); } } else { if (bucket == null) { bucket = new HeaderBucket(null, null); } bucket.Values.Add(value ?? string.Empty); } if (first_entry) { headers.Add(name, bucket); } } return(ok); }
internal bool AddValue(string value, HeaderInfo headerInfo, bool ignoreInvalid) { return(AddInternal(headerInfo.Name, new [] { value }, headerInfo, ignoreInvalid)); }
protected override object CreateCollection(HttpHeaders headers, HeaderInfo headerInfo) { return(new HttpHeaderValueCollection <U> (headers, headerInfo)); }
internal HttpHeaderValueCollection(HttpHeaders headers, HeaderInfo headerInfo) { list = new List <T> (); this.headers = headers; this.headerInfo = headerInfo; }
protected abstract object CreateCollection(HttpHeaders headers, HeaderInfo headerInfo);