public Add ( |
||
header | Header to be added. | |
Résultat |
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); }
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); }
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); }
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"); }
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)); }
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)); }
/// <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); }
/// <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; }