Beispiel #1
0
 protected override object CreateCollection(HttpHeaders headers, HeaderInfo headerInfo)
 {
     return(new HttpHeaderValueCollection <U> (headers, headerInfo));
 }
Beispiel #2
0
 protected abstract object CreateCollection(HttpHeaders headers, HeaderInfo headerInfo);
Beispiel #3
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.AddToCollection(bucket.Parsed, parsed_value);
                    }
                    else
                    {
                        if (bucket != null)
                        {
                            throw new FormatException();
                        }

                        bucket = new HeaderBucket(parsed_value);
                    }
                }
                else
                {
                    if (bucket == null)
                    {
                        bucket = new HeaderBucket(null);
                    }

                    bucket.Values.Add(value ?? string.Empty);
                }

                if (first_entry)
                {
                    headers.Add(name, bucket);
                }
            }

            return(ok);
        }
 internal HttpHeaderValueCollection(HttpHeaders headers, HeaderInfo headerInfo)
 {
     list            = new List <T> ();
     this.headers    = headers;
     this.headerInfo = headerInfo;
 }
Beispiel #5
0
 internal bool AddValue(string value, HeaderInfo headerInfo, bool ignoreInvalid)
 {
     return(AddInternal(headerInfo.Name, new [] { value }, headerInfo, ignoreInvalid));
 }