URSA.Web.Http.HeaderCollection.Add C# (CSharp) Method

Add() public method

Adds a new header.
If the header already exists, method will merge new value and parameters with the existing ones.
public Add ( Header header ) : Header
header Header Header to be added.
return Header
        public Header Add(Header header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            Header result;
            if (!_headers.TryGetValue(header.Name, out result))
            {
                _headers[header.Name] = result = header;
            }
            else
            {
                header.Values.ForEach(value => result.Values.AddUnique(value));
            }

            return result;
        }

Same methods

HeaderCollection::Add ( string name, string value ) : Header

Usage Example

示例#1
0
        public void it_should_serialize_the_headers_to_its_string_representation()
        {
            HeaderCollection headers = new HeaderCollection();
            headers.Add(new Header("Header1", new[] { new HeaderValue("Value1", new HeaderParameter("Parameter1", "ParameterValue1")) }));
            headers.Add(new Header("Header2", new[] { new HeaderValue("Value2", new HeaderParameter("Parameter2", "ParameterValue2")) }));

            string expected = String.Format("{0}\r\n{1}\r\n\r\n", headers["Header1"], headers["Header2"]);
            headers.ToString().Should().Be(expected);
        }
All Usage Examples Of URSA.Web.Http.HeaderCollection::Add