public void GetAllDontCombineSetCookie() { CombinedHttpHeaders headers = NewCombinedHttpHeaders(); headers.Add(HttpHeaderNames.SetCookie, "a"); headers.Add(HttpHeaderNames.SetCookie, "b"); Assert.Equal(2, headers.GetAll(HttpHeaderNames.SetCookie).Count); Assert.Equal(new List <string>(new[] { "a", "b" }), headers.GetAll(HttpHeaderNames.SetCookie).Select(_ => _.ToString()).ToList()); }
public void DontCombineSetCookieHeadersRegardlessOfCase() { CombinedHttpHeaders headers = NewCombinedHttpHeaders(); headers.Add(AsciiString.Of("Set-Cookie"), "a"); CombinedHttpHeaders otherHeaders = NewCombinedHttpHeaders(); otherHeaders.Add(AsciiString.Of("set-cookie"), "b"); otherHeaders.Add(AsciiString.Of("SET-COOKIE"), "c"); headers.Add(otherHeaders); var list = headers.GetAll(HttpHeaderNames.SetCookie); Assert.Equal(3, headers.GetAll(HttpHeaderNames.SetCookie).Count); }
public void AddIterableCsvEmpty() { CombinedHttpHeaders headers = NewCombinedHttpHeaders(); headers.Add(HeaderName, new List <ICharSequence>()); Assert.Equal(0, headers.GetAll(HeaderName).Count); }
public void AddCharSequencesCsvWithValueContainingCommas() { CombinedHttpHeaders headers = NewCombinedHttpHeaders(); headers.Add(HeaderName, HeaderValue.Eight.Subset(6)); Assert.True(ContentEquals((StringCharSequence)HeaderValue.Eight.SubsetAsCsvString(6), headers.Get(HeaderName, null))); Assert.Equal(HeaderValue.Eight.Subset(6), headers.GetAll(HeaderName)); }
public void DontCombineSetCookieHeaders() { CombinedHttpHeaders headers = NewCombinedHttpHeaders(); headers.Add(HttpHeaderNames.SetCookie, "a"); CombinedHttpHeaders otherHeaders = NewCombinedHttpHeaders(); otherHeaders.Add(HttpHeaderNames.SetCookie, "b"); otherHeaders.Add(HttpHeaderNames.SetCookie, "c"); headers.Add(otherHeaders); Assert.Equal(3, headers.GetAll(HttpHeaderNames.SetCookie).Count); }
static void AssertCsvValues(CombinedHttpHeaders headers, HeaderValue headerValue) { Assert.True(ContentEquals(headerValue.AsCsv(), headers.Get(HeaderName, null))); List <ICharSequence> expected = headerValue.AsList(); IList <ICharSequence> values = headers.GetAll(HeaderName); Assert.Equal(expected.Count, values.Count); for (int i = 0; i < expected.Count; i++) { Assert.True(expected[i].ContentEquals(values[i])); } }
public void OwsTrimming() { CombinedHttpHeaders headers = NewCombinedHttpHeaders(); headers.Set(HeaderName, new List <ICharSequence> { (StringCharSequence)"\ta", (StringCharSequence)" ", (StringCharSequence)" b ", (StringCharSequence)"\t \t" }); headers.Add(HeaderName, new List <ICharSequence> { (StringCharSequence)" c, d \t" }); var expected = new List <ICharSequence> { (StringCharSequence)"a", (StringCharSequence)"", (StringCharSequence)"b", (StringCharSequence)"", (StringCharSequence)"c, d" }; IList <ICharSequence> actual = headers.GetAll(HeaderName); Assert.True(expected.SequenceEqual(actual)); Assert.Equal("a,,b,,\"c, d\"", headers.Get(HeaderName, null)?.ToString()); Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"a", true)); Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)" a ", true)); Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"a", true)); Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"a,b", true)); Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)" c, d ", true)); Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"c, d", true)); Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)" c ", true)); Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"d", true)); Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"\t", true)); Assert.True(headers.ContainsValue(HeaderName, (StringCharSequence)"", true)); Assert.False(headers.ContainsValue(HeaderName, (StringCharSequence)"e", true)); CombinedHttpHeaders copiedHeaders = NewCombinedHttpHeaders(); copiedHeaders.Add(headers); Assert.Equal(new List <ICharSequence> { (StringCharSequence)"a", (StringCharSequence)"", (StringCharSequence)"b", (StringCharSequence)"", (StringCharSequence)"c, d" }, copiedHeaders.GetAll(HeaderName)); }
public void GetAll() { CombinedHttpHeaders headers = NewCombinedHttpHeaders(); headers.Set(HeaderName, new List <ICharSequence> { (StringCharSequence)"a", (StringCharSequence)"b", (StringCharSequence)"c" }); var expected = new ICharSequence[] { (StringCharSequence)"a", (StringCharSequence)"b", (StringCharSequence)"c" }; IList <ICharSequence> actual = headers.GetAll(HeaderName); Assert.True(expected.SequenceEqual(actual)); headers.Set(HeaderName, new List <ICharSequence> { (StringCharSequence)"a,", (StringCharSequence)"b,", (StringCharSequence)"c," }); expected = new ICharSequence[] { (StringCharSequence)"a,", (StringCharSequence)"b,", (StringCharSequence)"c," }; actual = headers.GetAll(HeaderName); Assert.True(expected.SequenceEqual(actual)); headers.Set(HeaderName, new List <ICharSequence> { (StringCharSequence)"a\"", (StringCharSequence)"b\"", (StringCharSequence)"c\"" }); expected = new ICharSequence[] { (StringCharSequence)"a\"", (StringCharSequence)"b\"", (StringCharSequence)"c\"" }; actual = headers.GetAll(HeaderName); Assert.True(expected.SequenceEqual(actual)); headers.Set(HeaderName, new List <ICharSequence> { (StringCharSequence)"\"a\"", (StringCharSequence)"\"b\"", (StringCharSequence)"\"c\"" }); expected = new ICharSequence[] { (StringCharSequence)"a", (StringCharSequence)"b", (StringCharSequence)"c" }; actual = headers.GetAll(HeaderName); Assert.True(expected.SequenceEqual(actual)); headers.Set(HeaderName, (StringCharSequence)"a,b,c"); expected = new ICharSequence[] { (StringCharSequence)"a,b,c" }; actual = headers.GetAll(HeaderName); Assert.True(expected.SequenceEqual(actual)); headers.Set(HeaderName, (StringCharSequence)"\"a,b,c\""); actual = headers.GetAll(HeaderName); Assert.True(expected.SequenceEqual(actual)); }
static void AssertCsvValue(CombinedHttpHeaders headers, HeaderValue headerValue) { Assert.True(ContentEquals((StringCharSequence)headerValue.ToString(), headers.Get(HeaderName, null))); Assert.True(ContentEquals((StringCharSequence)headerValue.ToString(), headers.GetAll(HeaderName)[0])); }