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
Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void it_should_add_a_header()
        {
            HeaderCollection headers = new HeaderCollection();
            headers.Add(new Header("Header1", new List<HeaderValue>(new[] { new HeaderValue("Value1", new HeaderParameter("Parameter1", "ParameterValue1")) })));
            headers.Add("Header1", "Value2");

            headers.Count.Should().Be(1);
            headers["Header1"].Values.Count.Should().Be(2);
            headers["Header1"].Values.First().Parameters.Count.Should().Be(1);
        }
Exemplo n.º 3
0
        public void it_should_remove_a_header()
        {
            HeaderCollection headers = new HeaderCollection();
            headers.Add(new Header("Header1", new[] { new HeaderValue("Value1", new HeaderParameter("Parameter1", "ParameterValue1")) }));
            headers.Remove("Header1");

            headers.Count.Should().Be(0);
        }
Exemplo n.º 4
0
        public void it_should_get_a_header_by_its_name()
        {
            HeaderCollection headers = new HeaderCollection();
            headers.Add(new Header("Header1", new[] { new HeaderValue("Value1", new HeaderParameter("Parameter1", "ParameterValue1")) }));

            Header header = headers["Header1"];

            header.Should().NotBeNull();
            header.Name.Should().Be("Header1");
        }
Exemplo n.º 5
0
        public ResponseInfo(Encoding encoding, RequestInfo request, params Header[] headers)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            Encoding = encoding;
            Request = request;
            _headers = new HeaderCollection();
            headers.ForEach(header => _headers.Add(header));
        }
Exemplo n.º 6
0
        public ResponseInfo(Encoding encoding, RequestInfo request, params Header[] headers)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            Encoding = encoding;
            Request  = request;
            _headers = new HeaderCollection();
            headers.ForEach(header => _headers.Add(header));
        }
Exemplo n.º 7
0
        /// <summary>Parses a given string as a <see cref="HeaderCollection" />.</summary>
        /// <param name="headers">String to be parsed.</param>
        /// <returns>Instance of the <see cref="HeaderCollection" />.</returns>
        public static HeaderCollection Parse(string headers)
        {
            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            if (headers.Length == 0)
            {
                throw new ArgumentOutOfRangeException("headers");
            }

            HeaderCollection result = new HeaderCollection();
            var matches             = Header.Matches(headers);

            foreach (Match match in matches)
            {
                result.Add(Http.Header.Parse(match.Value));
            }

            return(result);
        }
Exemplo n.º 8
0
        /// <summary>Parses a given string as a <see cref="HeaderCollection" />.</summary>
        /// <param name="headers">String to be parsed.</param>
        /// <returns>Instance of the <see cref="HeaderCollection" />.</returns>
        public static HeaderCollection Parse(string headers)
        {
            if (headers == null)
            {
                throw new ArgumentNullException("headers");
            }

            if (headers.Length == 0)
            {
                throw new ArgumentOutOfRangeException("headers");
            }

            HeaderCollection result = new HeaderCollection();
            var matches = Header.Matches(headers);
            foreach (Match match in matches)
            {
                result.Add(Http.Header.Parse(match.Value));
            }

            return result;
        }