コード例 #1
0
        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);
        }
コード例 #2
0
 internal bool AddValue(string value, HeaderInfo headerInfo, bool ignoreInvalid)
 {
     return(AddInternal(headerInfo.Name, new [] { value }, headerInfo, ignoreInvalid));
 }
コード例 #3
0
 protected override object CreateCollection(HttpHeaders headers, HeaderInfo headerInfo)
 {
     return(new HttpHeaderValueCollection <U> (headers, headerInfo));
 }
コード例 #4
0
 internal HttpHeaderValueCollection(HttpHeaders headers, HeaderInfo headerInfo)
 {
     list            = new List <T> ();
     this.headers    = headers;
     this.headerInfo = headerInfo;
 }
コード例 #5
0
 protected abstract object CreateCollection(HttpHeaders headers, HeaderInfo headerInfo);